'{'之前的预期类名 [英] expected class-name before '{'
问题描述
我有大约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 ?!?
推荐答案
bubzilla写道:
bubzilla wrote:
i have有大约10个带有实现类的头文件。现在,当我尝试使用
来编译它们时,我收到以下消息:
在Proxy / ServerCnx.hh中包含的文件中:36,
$来自Proxy / Payload.hh的b $ b:30,
...
来自main.cc的
代理/接口.hh :83:错误:在''{''
之前预期的类名称。接口.hh看起来像这样:
class模块: public ClientCnx {...}
到目前为止,我认为ClientCnx没有声明。所以我尝试使用
class 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;
$ $
制作前瞻声明
b
$ b这里的前向声明是不够的,编译器需要看到基类的整个声明
。
A forward declaration isn''t sufficient here, the compiler needs to see
the whole declaration of the base classes.
>
但是现在,编译器说:
代理/接口.h.h:83:error_无效使用未定义类型`ClientCnx`
代理/接口.hh:30:错误_提前声明`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 ?!?
找到声明基类的头文件,并在
模块声明之前包含它。
问候,
Stuart
Find the header file that declares the base class and include it before
the declaration of Module.
Regards,
Stuart
bubzilla写道:
bubzilla wrote:
i已经有大约10个带有实现类的头文件。现在,当我尝试编译它们时,我得到以下消息:
在Proxy / ServerCnx.hh中包含的文件中:36,<来自Proxy / Payload.hh的
:30,
...
from main.cc:28
代理/Interface.hh:83:错误:在''{''
之前的预期类名.Interface.hh看起来像这样:
class Module:public ClientCnx {...}
到目前为止,我实现了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.
这肯定听起来像是一个合理的结论。
That certainly sounds like a reasonable conclusion.
所以我试图做出前瞻声明
So I tried to make a forward Declaration
但为什么你认为前瞻性声明有帮助?
But why do you think a forward declaration would help?
使用
类ClientCnx;
但是现在,编译器说:
Proxy / Interface.hh:83:error_ invalid use未定义的类型`ClientCnx`
代理/接口.h.h:30:错误_客户端解密`ClientCnx`
现在该怎么办?解决这个问题?!?
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 ?!?
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
好的,我有同样的解决方案。所以我试图更改标题包括,
但是有些我怎么做到了没有错误出现的方式!
所以,我必须尝试再次,找到合适的包括订单。
或者可能是因为有一些圈子需要以其他方式解决?
a? />
我不熟悉编译器如何将头文件放在一起?
Ok, i had the same solution. So i tried to change the header includes,
but some how i did got a way so that no error appears!
so, do i have to try again, to find the right include order.
Or can it be that there is somekind of circle that has to be solved in
a other way?
I''m not familiar how the Compiler brings the headerfiles together?
这篇关于'{'之前的预期类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!