记录错误:c++编译 error: expected class-name before ‘{’ token

error: expected class-name before ‘{’ token

错误结果:未包含相应头文件。

原因记录:在编程过程中,会引用到大量的头文件,其中某些头文件包含一些基础的类,在编写新的功能时可能会引用包含基础类的头文件,而导致没有引用基础类就能够正常编译程序。但当引用的头文件因为某些原因不被引用了,删除之后就会因为缺少基础类而不能编译成功。从而报告这个错误。

栗子:

线程基类

class MTHread

{};

应用1读线程

#include MTHread.h

class ReadThread:public MTHread

{};

应用2写线程

#include ReadThread.h

class WriteThread:public MTHread

{};

注意:若在应用2写线程中,至引用了读线程头文件,而未引用线程基类头文件,当把读线程头文件删除时,则会出现标题所示错误。

当然,每个人遇到的问题不同,千万不要拘泥于网络上提供的解决方案,一定要全面把握程序,分块排除问题。

a.cpp:35:5: error: extra qualification ‘Stud::’ on member ‘sum’ [-fpermissive] 35 | int Stud::sum=0; | ^~~~ a.cpp:35:15: error: ‘int Stud::sum’ conflicts with a previous declaration 35 | int Stud::sum=0; | ^ a.cpp:15:19: note: previous declaration ‘double Stud::sum’ 15 | static double sum; | ^~~ a.cpp:36:5: error: extra qualification ‘Stud::’ on member ‘num’ [-fpermissive] 36 | int Stud::num=0; | ^~~~ a.cpp:45:2: error: expected ‘}’ at end of input 45 | } | ^ a.cpp:9:12: note: to match this ‘{’ 9 | class Stud { | ^ a.cpp: In member function ‘void Stud::print()’: a.cpp:28:24: error: expected primary-expression before ‘,’ token 28 | cout <<number<<, name<<, score<< endl; | ^ a.cpp:28:32: error: expected primary-expression before ‘,’ token 28 | cout <<number<<, name<<, score<< endl; | ^ a.cpp:28:39: error: invalid operands of types ‘float’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’ 28 | cout <<number<<, name<<, score<< endl; | ~~~~~^~~~~~~ a.cpp: In member function ‘int Stud::main()’: a.cpp:40:8: error:class Stud’ has no member named ‘disp’ 40 | s1.disp(); | ^~~~ a.cpp:41:8: error:class Stud’ has no member named ‘disp’ 41 | s2.disp(); | ^~~~ a.cpp:42:8: error:class Stud’ has no member named ‘disp’ 42 | s3.disp(); | ^~~~ a.cpp:43:25: error: ‘avg’ is not a member of ‘Stud’ 43 | cout<<"avg="<<Stud::avg()<<endl; | ^~~ a.cpp: At global scope: a.cpp:45:2: error: expected unqualified-id at end of input 45 | } | ^
最新发布
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值