【发布时间】:2010-12-24 00:32:19
【问题描述】:
我在以下 c++ 程序中使用 operator == 时遇到了一些问题。
#include < iostream>
using namespace std;
class A
{
public:
A(char *b)
{
a = b;
}
A(A &c)
{
a = c.a;
}
bool operator ==(A &other)
{
return strcmp(a, other.a);
}
private:
char *a;
};
int main()
{
A obj("test");
A obj1("test1");
if(obj1 == A("test1"))
{
cout<<"This is true"<<endl;
}
}
if(obj1 == A("test1")) 行有什么问题??任何帮助表示赞赏。
【问题讨论】:
标签: c++ operators equals-operator