我专注于数据类型的'less'(谓词).
代码如下所示:
template<>
struct std::less<DateTimeKey>
{
bool operator()(const DateTimeKey& k1, const DateTimeKey& k2) const
{
// Some code ...
}
}
Run Code Online (Sandbox Code Playgroud)
编译时(在Ubuntu 9.10上使用g ++ 4.4.1),我得到错误:
不同命名空间中'template struct std :: less'的专业化
我做了一些研究,发现有一个'解决方法'涉及将特化包装在std命名空间中 - 即将代码更改为:
namespace std {
template<>
struct less<DateTimeKey>
{
bool operator()(const DateTimeKey& k1, const DateTimeKey& k2) const
{
// Some code ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
确实,关闭了编译器.然而,这个解决方案来自一个5岁的职位(由'伟大的'Victor Bazarof而不是[双关语]).这个解决方案还有很长的路要走,还是有更好的方法来解决这个问题,还是"老方法"仍然有效?
我得到关于我的Vec2操作员的断言失败<,我不知道有什么问题.
bool Vec2::operator<( const Vec2& v ) const
{
if(x < v.x)
return true;
else
return y < v.y;
}
Run Code Online (Sandbox Code Playgroud)
无效的运算符<用于标准集插入
template<class _Pr, class _Ty1, class _Ty2> inline
bool __CLRCALL_OR_CDECL _Debug_lt_pred(_Pr _Pred, const _Ty1& _Left, const _Ty2& _Right,
const wchar_t *_Where, unsigned int _Line)
{ // test if _Pred(_Left, _Right) and _Pred is strict weak ordering
if (!_Pred(_Left, _Right))
return (false);
else if (_Pred(_Right, _Left))
_DEBUG_ERROR2("invalid operator<", _Where, _Line);
return (true);
}
Run Code Online (Sandbox Code Playgroud)
谢谢