【发布时间】:2011-01-17 15:03:25
【问题描述】:
我正在使用 fstream,但出现了一些错误。
这是我所拥有的:
class CLog
{
void printOn(std::ostream& dbg) const;
}
void operator>>(const CLog& s, std::ofstream& dbg)
{
s.printOn(dbg);
}
但是当我编译时出现以下错误:
error C2664: 'printOn' : cannot convert parameter 1 from
'class std::basic_ofstream<char,struct std::char_traits<char> >' to
'class std::basic_ostream<char,struct std::char_traits<char> > &'
A reference that is not to 'const' cannot be bound to a non-lvalue
我以为 ofstream 继承自 ostream 那为什么不可能呢?
谢谢
【问题讨论】:
-
阿格!发现了一个丢失的
#include <fstream>。编译器的输出多么愚蠢。谢谢大家
标签: c++ inheritance iostream