请问高手关于重载操作符“<<”的简单问题,100分
//我编写了一个类需要重载操作符"<<",如下
class myclass{
...
friend ostream & operator<<(ostream &,const myclass &);
public :
...
char * to_str(){ return _string;}
private
...
char * _string;
}
//操作符函数定义如下
ostream& operator<<(ostream & os,const myclass &myc)
{ //为什么不能用如下的语句
//os<<myc.to_str();
os<<myc._string;
return os;
}
我想问的是为什么我用"os<<myc.to_str()"输出时编译出如下错误
passing `const myclass' as `this' argument of `char * myclass::to_str()' discards qualifiers
谢谢!