std::ostream& operator<<(std::ostream& os, const Token& token){
os << 1;
return os;
}
报错信息是这样的 :
/Users/zhangzhimin/ClionProjects/Fred/Font/Lexer/Token.cpp:33:8: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'int')
os << 1;
~~ ^ ~
/Users/zhangzhimin/ClionProjects/Fred/Font/Lexer/Token.cpp:32:15: note: candidate function not viable: no known conversion from 'int' to 'const Token' for 2nd argument
std::ostream& operator<<(std::ostream& os, const Token& token){
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:5382:1: note: candidate template ignored: could not match 'shared_ptr<type-parameter-0-2>' against 'int'
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:4151:1: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'int'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
1 error generated.
make[2]: *** [CMakeFiles/Fred.dir/Font/Lexer/Token.cpp.o] Error 1
make[1]: *** [CMakeFiles/Fred.dir/all] Error 2
make: *** [all] Error 2
看不到你其他程式碼不能全面的了解情況,從僅有的片段來看是由重載了全局的
<<
運算符導致的錯誤。