我试图定义运算符<<在课堂上。这是一个操纵者。 endl是iostream的操纵者。我的操纵者是my_endl。
my_endl的详细信息目前非常重要,所以我把它们排除了。
class FStream {
public:
FStream();
~FStream();
};
FStream::FStream() {
}
FStream::~FStream() {
}
class DerivedFStream : FStream {
public:
DerivedFStream();
~DerivedFStream();
static DerivedFStream& my_endl(DerivedFStream& dfs);
};
DerivedFStream::DerivedFStream() : FStream() {
}
DerivedFStream::~DerivedFStream() {
}
DerivedFStream& DerivedFStream::my_endl(DerivedFStream& dfs) {
return dfs;
};
int main() {
DerivedFStream f = DerivedFStream();
DerivedFStream& rf = f;
rf << DerivedFStream::my_endl;
return 0;
};
编译时我得到了
DerivedStream.cpp: In function ‘int main()’:
DerivedStream.cpp:43:8: error: no match for ‘operator<<’ (operand types are ‘DerivedFStream’ and ‘DerivedFStream&(DerivedFStream&)’)
rf << DerivedFStream::my_endl;
^
我从错误信息中得到的印象是考虑变量&#39; rf&#39;成为DerivedFStream&#39;而不是DerivedFStream&amp;&#39;。
建议请...