#include <iostream> using namespace std; class fulei { public: void fun1(); void fun2(); protected: private: }; class zilei:public fulei { public: void fun3(); void fun4(); protected: private: }; void fulei::fun1() { cout << "调用基类的fun1()" << endl; } void fulei::fun2() { cout << "调用基类的fun2()" << endl; } void zilei::fun3() { cout << "调用派生类的fun1()" << endl; } void zilei::fun4() { cout << "调用派生类的fun2()" << end; } int main() { cout << "主函数执行" << endl; cin.get(); return 0; }
为什么这段断码会报错?而把
void zilei::fun3() //{ // cout << "调用派生类的fun1()" << endl; //} // //void zilei::fun4() //{ // cout << "调用派生类的fun2()" << end; //}
这段代码注释掉就不会报错?是什么原因?麻烦大家指点一下?实在找不出什么原因?
g:\computer\cpp\studio\virtualclass2\virtualclass2\virtualclass2.cpp(39): error C2679: 二进制“<<”: 没有找到接受“overloaded-function”类型的右操作数的运算符(或没有可接受的转换)
1> e:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(695): 可能是“std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)”
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> e:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(742): 或 “std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)”
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
40
cout << "调用派生类的fun2()" << endl;
第39行,最后endl而不是end