大家帮忙看看是怎么回事?怎么回事这样
#include<string>
using namespace std;
class testq
{
private:
string name;
public:
testq(string inn){name=inn;};
friend bool operator == ( testq n1,testq n2);
};
bool operator ==(testq n1,testq n2)
{
if(n1.name==n2.name)
return true;
else
{
return false;
}
}
main()
{
}
这么写出现错误
Compiling...
test.cpp
E:\project\testlist\test.cpp(18) : error C2248: 'name' : cannot access private member declared in class 'testq'
E:\project\testlist\test.cpp(8) : see declaration of 'name'
E:\project\testlist\test.cpp(18) : error C2248: 'name' : cannot access private member declared in class 'testq'
E:\project\testlist\test.cpp(8) : see declaration of 'name'
E:\project\testlist\test.cpp(28) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
test.obj - 1 error(s), 0 warning(s)
把name改为public后就没有事了,这是怎么回事?