【发布时间】:2013-10-16 07:18:19
【问题描述】:
我在 ULong.h 中声明了这些原型
bool operator== (const ULong& ) const;
bool operator== (unsigned long long) const;
friend bool operator== (unsigned long long, const ULong&);
在 ULong.cpp 中,我正在尝试实现它们:
bool ULong::operator== (const ULong& ul) const
{
if(_num_digits != ul._num_digits)
return false;
for(unsigned i = 0;i < _num_digits; i++)
{
if(_number[i] != ul._number[i])
return false;
}
return true;
}
bool ULong::operator== (unsigned long long l) const
{
return *this == ULong(l);
}
ULong operator== (unsigned long long l, const ULong& ul)
{
return ULong(l) == ul;
}
我得到编译器错误:
ULong.cpp:358:56:错误:新声明'ULong operator==(long long unsigned int, const ULong&)’ 在 ULong.cpp:10:0 中包含的文件中:
ULong.h:76:15:错误:混淆旧声明'bool operator==(long long unsigned int, const ULong&)'
我不明白如何正确实现这个方法。
【问题讨论】: