代码改变世界

error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'

2014-02-15 20:38  hongjiumu  阅读(557)  评论(0编辑  收藏  举报
std::ostream & operator<<(std::ostream os,const MyString & mystr)
{
os<<mystr.pCharArray;
return os;
};
编译出错;
error C2248: 'MyString::pCharArray' : cannot access private member declared in class 'MyString'
修改:
std::ostream & operator<<(std::ostream & os,const MyString & mystr)
{
os<<mystr.pCharArray;
return os;
};
OK!
I've been bitten on the bum by this numerous times; the definition of your operator overload doesn't quite match the declaration, so it is thought to be a different function.
The signatures don't match. Your non-member function takes fun& fun, the friend declared on takes const fun& fun.