g++重载operator《遇到的坑

在VS里编译可以通过,到了codelite 就一直报错

//重载操作符<<
    friend ostream& operator<<(ostream &os,MyString &str);

后来经过查询源码,找到了原因

可能原因,vs++内部会做优化,自动加上const,g++编译器是严格匹配

  //重载操作符<<
    friend ostream& operator<<(ostream &os,const MyString &str);

改成这样就可以编译通过了。

发布了27 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/jfztaq/article/details/82421992
g++