请教:关于操作符<<重载!
shglt 2003-09-13 07:16:05 #include <iostream>
#include <string>
using namespace std;
class CBase
{
public:
CBase(){}
virtual ~CBase(){}
friend ostream& operator<<(ostream &os, const CBase &rhs);
private:
string m_strData;
}
ostream& operator<<(ostream &os, const CBase &rhs)
{
os<<rhs.m_strData<<endl;
return os;
}
int main(void)
{
CBase aBase;
cout<<aBase;
return 0;
}
在Visual C++ 6.0中提示:
1.不能访问私有成员!----而我的operator<<定义的是友元啊,怎么不能访问呢?
2.<< is ambiguous! ----有二义行吗? string中重载了<<啊!
望各位大侠指教!
谢谢!