操作符过载问题
Operator overload problems
在person.h中,在名为person的类的公共部分下,我有如下内容:
bool operator < (person& currentPerson);
In person.cpp我有这个:
bool person::operator < (person& currentPerson)
{
return age < currentPerson.age;
}
当我编译它时,我得到一个链接器错误,但只有当我实际使用操作符时。有人能告诉我我哪里做错了吗?
错误信息如下。
1>FunctionTemplates.obj : error LNK2019: unresolved external symbol "public: bool __thiscall person::operator<(class person const &)" (??Mperson@@QAE_NABV0@@Z) referenced in function "class person __cdecl max(class person &,class person &)" (?max@@YA?AVperson@@AAV1@0@Z)
1>c:userskennethdocumentsvisual studio 2012ProjectsFunctionTemplatesDebugFunctionTemplates.exe : fatal error LNK1120: 1 unresolved externals
在代码的某个地方,当使用函数max
时,您正在将一个人与临时人员进行比较。要做到这一点,你需要接受const引用。
bool operator < (const person& currentPerson) const;
^^^^ ^^^^^^ //This wont hurt too
和
bool person::operator < (const person& currentPerson)
// ^^^^^
{
return age < currentPerson.age;
}
相关文章:
- 在使用放置新操作符时,我真的需要担心对齐问题吗
- Assert()函数抛出一个错误——操作符有问题
- 操作符+重载问题
- 下标操作符重载:返回引用问题
- 操作符重载问题
- 操作符重载问题
- 关于操作符new()和操作符delete()的问题
- c++操作符重载性能问题
- c++中切换操作符的问题
- 操作符重载问题
- 涉及数组指针时delete[]操作符的问题
- 编译问题相等/不相等操作符
- 操作符过载问题
- 矩阵类操作符重载,析构函数问题
- 类赋值操作符=问题
- c++ boost::线程操作符()()问题
- 关于()操作符重载的问题
- 关于模板中随机访问迭代器的操作符+重载的问题
- 三元操作符的指针转换问题
- 基类中操作符重载的问题