我专注于数据类型的'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而不是[双关语]).这个解决方案还有很长的路要走,还是有更好的方法来解决这个问题,还是"老方法"仍然有效?
c++ ×1