![](/img/trans.png)
[英]uint64_t or int64_t not found error when compiling 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)中,這應該可以正常編譯(根據其倉庫https://github.com/yage99/tfs )。 它是GCC 7.3.0的新功能嗎?
從C ++ 11開始, std::ostream
到bool
的轉換被標記為explicit
。 在return
語句中不考慮顯式轉換; 您需要顯式轉換。
附帶說明:傳統上,用於插入流中的operator<<
重載的返回類型為std::ostream&
。 這允許插入鏈接,例如std::cout << foo << bar
。 您的operator<<
重載通常也應該是一個自由函數,而不是成員。 成員不允許使用標准stream << object
語法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.