iostream我有一个通过模板支持 -syntax的自定义日志记录类operator <<:
template< class T >
MyLoggingClass & operator <<(MyLoggingClass &, const T &) {
// do stuff
}
我也有这个操作符的专门版本,应该在日志消息完成时调用:
template< >
MyLoggingClass & operator <<(MyLoggingClass &, consts EndOfMessageType &){
// build the message and process it
}
EndOfMessageType定义如下:
class EndOfMessageType {};
const EndOfMessageType eom = EndOfMessageType( );
定义了全局常量eom,以便用户可以像std::endl在日志消息末尾一样使用它。我的问题是,这个解决方案是否有任何陷阱,或者是否有一些既定的模式可以做到这一点?
提前致谢!