我写了一个String类,定义如下:
class String
{
friend bool operator==(const String&,const String&);
friend bool operator==(const String&,const char*);
........
..........
private:
char* _char;
int _size;
..........
public:
.........
.........
};
operator== 定义如下:
bool operator==(const String &str,const String &str1)
{
if(str._size!=str1._size)
return false;
else
{
return strcmp(str._char,str1._char)? false:true;
}
}
但编译器却报错:
error C2248: '_size' : cannot access private member declared in class 'String'
请问各位是为什么啊?谢谢先
为什么声明了friend却不能访问private member?