问题描述
我有大约10个带有实现类的头文件。现在,当我尝试编译它们时,我会收到以下消息:
来自Proxy / ServerCnx.hh的文件:36,
$来自Proxy / Payload.hh的b $ b:30,
...
来自main.cc的
代理/接口.hh :83:错误:在''{''
之前的预期类名.Interface.hh看起来像这样:
class模块:public ClientCnx {...}
到目前为止,我认为ClientCnx没有声明。所以我试图通过使用
类ClientCnx来生成前瞻性声明
;
但是现在,编译器说:
Proxy / Interface.hh:83:error_无效使用未定义类型`ClientCnx`
代理/接口.h.h:30:error_ forward声明'ClientCnx`
现在我可以做些什么来解决这个问题?!?
Hi,
i′ve got about 10 headerfiles with implemented classes. Now when i try
to compile them i get the following message:
In file included from Proxy/ServerCnx.hh:36,
from Proxy/Payload.hh:30,
...
from main.cc:28
Proxy/Interface.hh:83: error: expected class-name before ''{''
The Interface.hh looks like this:
class Module : public ClientCnx{...}
so far, i realisied that ClientCnx isn′t declarated. So I tried to
make a forward Declaration
by using
class ClientCnx;
but now, the compiler says:
Proxy/Interface.hh:83: error_ invalid use of undefined type `ClientCnx`
Proxy/Interface.hh:30: error_ forward declaration of `ClientCnx`
now what can i do to fix this prob ?!?
推荐答案
$ $
制作前瞻声明
b
$ b这里的前向声明是不够的,编译器需要看到基类的整个声明
。
A forward declaration isn''t sufficient here, the compiler needs to see
the whole declaration of the base classes.
找到声明基类的头文件,并在
模块声明之前包含它。
问候,
Stuart
Find the header file that declares the base class and include it before
the declaration of Module.
Regards,
Stuart
这肯定听起来像是一个合理的结论。
That certainly sounds like a reasonable conclusion.
但为什么你认为前瞻性声明有帮助?
But why do you think a forward declaration would help?
ClientCnx是Module的基类,编译器在看到Module之前需要知道ClientCnx的完整定义。前向
声明只告诉编译器ClientCnx是
类的名称。这还不够。您需要包含ClientCnx的整个类
定义。如果ClientCnx是在标题中定义的,那么#include
那个标题高于类Module的定义。
Gavin Deane
ClientCnx is a base class of Module and the compiler needs to know the
full definition of ClientCnx before it sees Module. A forward
declaration just tells the compiler that ClientCnx is the name of a
class. That is not enough. You need to include the entire class
definition of ClientCnx. If ClientCnx is defined in a header, #include
that header above the definition of class Module.
Gavin Deane
这篇关于'{'之前的预期类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!