类正向声明失败,无递归包含
Class forward declaration fails, No recursive include
我正在使用VS2008,并在MFC中为一个学校项目进行开发。代码结构是由bouml 4生成的,当我想使用它时,出现了问题。我已经被错误C2061:语法错误:标识符"节点"卡住了几个小时,不知道如何解决它。这里是发生编译错误的地方。
Link.h
#pragma once
#include "model/MapIndicator.h"
#include "model/Highlightable.h"
class Node;
struct COORDINATE_AREA;
class Link : public MapIndicator {
public:
explicit Link();
Link(Node * node1, Node * node2); // Error on this line
protected:
Link(const Link & source);
public:
virtual ~Link();
...
节点.h
#pragma once
#include "model/MapIndicator.h"
#include <vector>
using std::vector;
#include "model/COORDINATE.h"
#include "model/Highlightable.h"
class Site;
struct COORDINATE_AREA;
//Node will be repaint several times in one refresh.
class Node : public MapIndicator {
public:
explicit Node();
protected:
Node(const Node & source);
public:
virtual ~Node();
private:
Node & operator=(const Node & source);
public:
//This function will only add other node in its adjacent node list.
//Note: Duplicate adding will have no effect.
void addAdjNode(Node * otherNode);
vector<Node *>::size_type getAdjNodeCount();
//Remove specified node from its adjacent node list.
//Return true if succeeds, Return false if that node doesn't exist in list.
bool removeAdjNode(const Node * adjNode);
//Add site which use this instance as reference node to referenced site list.
void addRefSite(Site * refSite);
vector<Site *>::size_type getRefSiteCount();
//Remove specified site from its referenced site list.
//Return true if succeeds, Return false if that site doesn't exist in list.
bool removeRefSite(const Site * refSite);
inline COORDINATE getNodeCoordinate() const;
void setNodeCoordinate(COORDINATE value);
//Draw itself according to the size and the coordinate of display area and its own coordinate.
virtual void DrawInRect(const RECT & viewDispRect, const COORDINATE_AREA & mapDispCoordinate, CDC * pDC);
//Return true if indicator have something to show in the coordinate area specified in parameter, otherwise return false.
virtual bool VisibleInArea(const COORDINATE_AREA & mapDispCoordinate);
//Return distance in double between screen position of this indicator and the screen point.
virtual double DistanceInPixel(const RECT & viewDispRect, const COORDINATE_AREA & mapDispCoordinate, const CPoint & point);
//Set display state directly.
virtual void SetDispState(DispState dispState);
//If hover is true and current state is normal, set state to hover.
//If hover is false and current state is hover, set state to normal.
//Otherwise no effect.
virtual void SetHover(bool hover);
private:
vector<Node *> adjNodes;
vector<Site *> referencedSites;
COORDINATE nodeCoordinate;
};
inline COORDINATE Node::getNodeCoordinate() const {
return nodeCoordinate;
}
MapIndicator.h
#pragma once
#include "model/MapObject.h"
#include "model/Drawable.h"
#include "model/Locatable.h"
#include "model/Highlightable.h"
struct COORDINATE_AREA;
//This enum specifies different kinds of indicators available to identify.
enum IndicatorType {
Road,
Link,
Node,
Site
};
//MapIndicator is a artifact on map given varies kinds of hint to user.
class MapIndicator : public MapObject, public Drawable, public Locatable, public Highlightable {
public:
explicit MapIndicator(IndicatorType indicatorType);
...
MapObject、Drawable、Locatable和Highlightable的标头中没有include语句,只有#pragma一次。
以及领先的编译输出:
1>Link.cpp
1>c:projectmodellink.h(12) : error C2061: syntax error : identifier 'Node'
1>c:projectmodellink.h(12) : error C2535: 'Link::Link(void)' : member function already defined or declared
1> c:projectmodellink.h(11) : see declaration of 'Link::Link'
事实上,这个错误在我的项目中随处可见,但为什么呢?我使用的是指针,没有递归包含。
好的,我发现我在MapIndicator.h中定义的枚举与类名有名称冲突。我必须感谢我们伟大的编译信息。。。OTL。。。
相关文章:
- 通过递归进行因子分解
- 递归函数计算序列中的平方和(并输出过程)
- 使用递归的数组的最小值.这是怎么回事
- 递归列出所有目录中的C++与Python与Ruby的性能
- 递归计数给定目录的文件和所有目录
- 如何在BST的这个简单递归实现中消除警告
- 包含模板文件的递归会导致编译失败
- 如何为想要公开相互递归函数的仅标头库组织包含
- 使用 Qt 标头的递归包含时出错
- 非递归 make:在循环中包含 makefile 段
- 递归包含自身列表的对象
- 包含自身实例化的模板,C++中的递归
- C++中的递归标头包含错误
- 类正向声明失败,无递归包含
- 内联函数不能包含递归、go to循环等
- c++递归检查number是否包含数字
- Boost / Netbeans: Linux Mint 17.2上与BSD相关的递归包含
- 为什么't my include保护防止递归包含和多个符号定义
- c++中的正向声明VS编译顺序错误,以避免包含递归标头
- Waf:递归地收集源文件并包含路径