Ben*_*Ben 4 c++ g++ operator-overloading
我们有一个自定义的Logging类,可以在VisualStudio 2010中编译好,但在Linux上使用g ++编译时会抛出错误.我们收到的错误消息如下:
Logger.hpp:84: error: declaration of "operator<<" as non-function
Logger.hpp:84: error: expected ";" before "(" token
Logger.hpp:91: error: expected ";" before "inline"
Logger.hpp:91: error: declaration of "operator<<" as non-function
Logger.hpp:91: error: expected ";" before "(" token
Logger.hpp:98: error: expected ";" before "typedef"
Run Code Online (Sandbox Code Playgroud)
各行代码如下:
/*:84*/inline Logger& operator<<(std::_Smanip<std::ios_base::fmtflags> output)
{
if (this->loggingEnabled())
std::cout << output;
return *this;
}
inline Logger& operator<<(std::_Smanip<std::streamsize> output)
{
if (this->loggingEnabled())
std::cout << output;
return *this;
}
typedef std::basic_ostream<char, std::char_traits<char> >& (*StdEndl)(std::basic_ostream<char, std::char_traits<char> >&);
inline Logger& operator<<(StdEndl output)
{
if (this->loggingEnabled())
std::cout << output;
return *this;
}
Run Code Online (Sandbox Code Playgroud)
重载<<运算符的其他方法工作正常,因此我的猜测是错误与参数type(std::_Smanip)有关; 关于为什么的任何线索?
谢谢,本
| 归档时间: |
|
| 查看次数: |
4710 次 |
| 最近记录: |