使用 GCC 7.3.0 时发生代码转换错误
Code converting error occurs using GCC 7.3.0
使用 GCC 7.3.0 时发生位移错误
In file included from show_factory.h:21:0,
from show.h:21,
from main.cpp:27:
common.h: In member function ‘bool tfs::tools::ServerInfo::operator<<(std::ostream&) const’:
common.h:173:22: error: cannot convert ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ to ‘bool’ in return
return os << server_id_;
^~~~~~~~~~
Makefile:630: recipe for target 'main.o' failed
如何更改此处的代码以使其安全无恙?
在 GCC 的旧版本 (<=5) 中,这应该编译得很好(根据他们的 repo https://github.com/yage99/tfs)。它是GCC 7.3.0的新功能吗?
std::ostream
自 C++11 以来标记为explicit
bool
。 return
语句中不考虑显式转换;您需要显式强制转换。
作为旁注:用于插入流operator<<
重载的返回类型传统上是std::ostream&
。 这允许链接插入,例如 std::cout << foo << bar
。 您的operator<<
重载通常也应该是一个自由函数,而不是一个成员。 成员不允许使用标准stream << object
语法。
相关文章:
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 将 OpenCV 2 中的ANN_MLP代码转换为 OpenCV 3 代码
- 将 c++ 代码转换为 python,使用运算符?
- 使用 jni 将返回带有模板的对象的 Java 代码转换为 c++
- 如何在 Poco 中将工作 HTTP 代码转换为 HTTPS
- 将C++代码转换为 R 代码以生成数据
- 如何将C++ lambda 函数代码转换为 C#?
- 将 python、numpy 和 scipy 代码转换为兼容C++代码?
- 将本机C 代码转换为Java
- 将C++非托管代码转换为 C#
- 将Qt的QML代码转换为C++
- 将此C 代码转换为MIPS
- 如何将此代码转换为两个以上的数字(计算HCF)
- 想要将此 Matlab 代码转换为 OpenCV 代码
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- 将阻止同步代码转换为异步
- 将视觉C 代码转换为Borland C 构建器
- 如何将VDT的Pade Exp fast_ex()的双重版本的标量代码转换为SSE2?
- 将 ML 代码转换为 C++