【发布时间】:2010-02-17 16:19:46
【问题描述】:
我专门针对数据类型使用“少”(谓词)。
代码如下所示:
template<>
struct std::less<DateTimeKey>
{
bool operator()(const DateTimeKey& k1, const DateTimeKey& k2) const
{
// Some code ...
}
};
编译时(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 ...
}
};
}
这确实会关闭编译器。但是,该解决方案来自一个 5 岁的帖子(由“伟大的”维克多·巴扎罗夫(Victor Bazarof)提出[双关语无意])。这个修复仍然是要走的路,还是有更好的方法来解决这个问题,或者“旧方法”仍然有效?
【问题讨论】:
-
过载
DateTimeKey::operator<?
标签: c++