我为我的 NS 添加了一个新补丁,我看到了这两个错误。有谁知道我能做什么?
error: specialization of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = _AlgorithmTime]' in different namespace
from definition of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = _AlgorithmTime]'
错误来自这段代码
typedef struct _AlgorithmTime {
// Round.
int round;
// Fase.
int fase;
// Valore massimo di fase.
int last_fase;
public:
_AlgorithmTime() {
round = 0;
fase = 0;
last_fase = 0;
}
// Costruttore.
_AlgorithmTime(int r, int f, int l) {
round = r;
fase = f;
last_fase = l;
}
// Costruttore.
_AlgorithmTime(const _AlgorithmTime & t) {
round = t.round;
fase = t.fase;
last_fase = t.last_fase;
}
// Operatore di uguaglianza.
bool operator== (struct _AlgorithmTime & t) {
return ((t.fase == fase) && (t.round == round));
}
// Operatore minore.
bool operator < (struct _AlgorithmTime & t) {
if (round < t.round)
return true;
if (round > t.round)
return false;
if (fase < t.fase)
return true;
return false;
}
// Operatore maggiore.
bool operator > (struct _AlgorithmTime & t) {
if (round > t.round)
return true;
if (round < t.round)
return false;
if (fase > t.fase)
return true;
return false;
}
void operator++ () {
if (fase == last_fase) {
round++;
fase = 0;
return;
}
fase++;
}
void operator-- () {
if (fase == 0) {
round--;
fase = last_fase;
return;
}
fase--;
}
}AlgorithmTime;
template<>
bool
std::less<AlgorithmTime>::operator()(const AlgorithmTime & t1, const AlgorithmTime & t2)const
{
if (t1.round < t2.round)
return true;
if (t1.round > t2.round)
return false;
if (t1.fase < t2.fase)
return true;
return false;
}
谢谢
最佳答案
如果你的专业std::less<AlgorithmTime>::operator()
在您的命名空间内,这可能是编译器所提示的 - 您需要在“全局”命名空间级别进行专门化。
顺便说一句,虽然特化很好std::less
,在你的情况下没有必要 - std::less<AlgorithmTime>
的标准定义将使用 AlgorithmTime::operator<()
完成它的工作。
关于c++ - NS c++编程中的一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3033058/