Ubuntu下C++编译出错如下
error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string<char>}’ through ‘...’
CPublicFunction::WriteLog("%s", ex.displayText());
改动如下:
CPublicFunction::WriteLog("%s", ex.displayText().c_str());
即在要打印的string后面加 .c_str()
编译即可通过~
本文介绍了在Ubuntu环境下遇到的C++编译错误,即无法通过类型传递对象的问题,并提供了相应的解决方案。通过将打印字符串转换为C风格字符串并使用.c_str()方法,成功解决了编译问题。
4万+

被折叠的 条评论
为什么被折叠?



