【发布时间】:2018-01-25 10:57:08
【问题描述】:
我正在尝试使用包装类在 C++ 中创建自己的日志记录类,在该包装类中我重载了 operator
class myostream {
public:
static int getlogLevel() {
return loglevel;
}
static void setlogLevel(int i) {
loglevel = i;
}
myostream(std::basic_ios& cout, int level)
: _cout(cout), _level(level)
{}
template<class T>
std::ostream& operator<<(T t) {
if(_level >= loglevel) {
_cout << loglevelcolor[_level] << loglevelname[_level] << " " << t << COL_RESET << std::endl;
}
return _cout;
}
private:
static int loglevel;
std::basic_ostream& _cout;
int _level;
};
【问题讨论】:
-
std::basic_ostream是一个模板,std::ostream可能是你想要的。 -
发布有关构建错误的问题时,请始终包含您遇到的错误。将它们作为文本完整完整地复制,然后将它们不加修改地粘贴到问题正文中。请花一些时间到read about how to ask good questions。
-
另外,尝试查找a good input/output reference 可能也会对您有所帮助。