今天写程序的时候, 遇到这样一个错误expected class-name before '{’ token 最后发现原来是我的头文件声明没有加. 继承时不要忘记加基类的头文件 [eric] 而且基类头文件要放在派生类的前面 错误: class Foo: public Bar // Foo is a subclass of Bar
{
// stuff
};
正确: #include "Bar.h" // this makes Bar recognized
class Foo: public Bar
{
// stuff
}; +++++++++++++++++++++++++++++++++++++++++ my example: class derivedCls1: public BaseCls
{ void func1();
void func2();
} // "#include BaseCls.h" <-- 这里基类的头文件要放在派生类前面, 否则就会报错 "#include derivedCls1.h" void anotherCls::func() { derivedCls1 * Cls1Ptr; Cls1Ptr->func1(); Cls1Ptr->func2(); } |
|