打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
g++报错原因分析:expected class

今天写程序的时候, 遇到这样一个错误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();
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
2013搜狗校园招聘笔试题
Qt: Qt源码分析之QObject
C ++ 虚函数探索笔记(1)
Qt核心剖析:信息隐藏
Q_D宏
python核心知识点1
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服