[英]I'm getting error: Missing ; before *, but I'm not missing it
I have commented everything out and the code now looks like this. 我已经注释掉了所有内容,现在代码看起来像这样。
//AOBSClass.h
#ifndef __AOBSCLASSHDR__
#define __AOBSCLASSHDR__
#include "IDriver.h"
#include "ActuationClass.h"
namespace AOBS
{
class AOBSClass
{
public:
AOBSClass(IDriver *driver);
~AOBSClass();
IDriver *drivers;
ActuationClass act;
private:
};
}
#endif
// ActuationClass.h
#ifndef __ACTUATIONCLASSHDR__
#define __ACTUATIONCLASSHDR__
#include "AOBSClass.h"
namespace AOBS
{
class ActuationClass
{
public:
ActuationClass();
~ActuationClass();
AOBSClass *aobs; // This line here
private:
};
}
#endif
I keep getting the errors below on the line shown above. 在上面显示的行中,我不断收到以下错误。 I have no idea what could be causing it.
我不知道是什么原因造成的。
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I'm using Visual Studio Express 2013. 我正在使用Visual Studio Express 2013。
The two files include each other! 这两个文件相互包含! Just put
刚放
class AOBSClass;
in the beginning of ActuationClass.h. 在ActuationClass.h的开头。
You have a circular dependency. 您具有循环依赖关系。
ActuationClass.h
includes AOBClass.h
and vice versa. ActuationClass.h
包含AOBClass.h
,反之亦然。
To resolve this, remove the #include "AOBClass.h"
in ActuationClass.h
and just forward declare the AOBSClass
. 要解决此问题,请在
ActuationClass.h
删除#include "AOBClass.h"
,然后向前声明AOBSClass
。
namespace AOBS
{
class AOBSClass; // Forward declare
class ActuationClass
{
public:
ActuationClass();
~ActuationClass();
AOBSClass *aobs;
private:
};
}
You have circular includes. 您有通函包括。 Both header files include each other.
两个头文件都包括在内。 Generally, includes should go one way, like a tree structure.
通常,包含应采用一种方式,如树形结构。
A includes B includes C, etc A包括B包括C等
Also, as noted by others: a forward declaration can help with this sort of thing 另外,正如其他人所指出的:前向声明可以帮助解决此类问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.