求大佬帮我分析下呗…

ICE丶L 2019-04-16 11:47:53
编译时会出现:stringOverload.cc:28:5: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘void’) cout<<s1.display()<<endl; #include<string.h> #include<iostream> using namespace std; class String{ public: String(string str) :_str(str) { cout<<"Sting()"<<endl; } String operator=(const String &str2){ return String(_str=str2._str);} void display()const{ cout<<_str<<endl; } private: string _str; }; int main(){ String s1("hello"); String s2("world"); cout<<"before overload"<<endl; cout<<s1.display()<<endl; //cout<<s2.display()<<endl; s1=s2; cout<<"after overload"<<endl; //cout<<s1.display()<<endl; //cout<<s2.display()<<endl; }
...全文
9 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,773

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧