目前我有3个课程,设置如下:
World.h
include "WorldObject.h"
class WorldObject;
class TextObject; // when this is added, compiles fine, but tobj is incomplete when accessed
//(world->tobj->function()). if #include "TextObject.h" is added, numerous errors occur within TextObject.h
class World {
public:
WorldObject* wobj; // works fine
TextObject* tobj; //trying to get this to be functional
};
WorldObject.h
#include "World.h"
class World;
class WorldObject {
public:
WorldObject(World* world){...} // works fine, world can be accessed from world objects
};
TextObject.h
#include "WorldObject.h"
#include "World.h"
class TextObject : WorldObject {
public:
TextObject(World* world) : WorldObject(w){...};
};
如何使用前向声明,以便可以像obj一样从World.h访问tobj,并且没有错误?在每个课程的开始,我也使用#pragma。我试图将“类世界”添加到TextObject.h,将“类TextObject”添加到World.h,但是看似标准的程序都没有起作用。有什么建议吗?