C++前向声明(指针) - 访问成员

zel*_*ing 0 c++ pointers class member forward-declaration

我正在使用OpenGL和DirectX,我已经开始为面向对象的游戏类开发基础知识.当前类的结构如下:

对象
--- | ---演员
--------- | ---典当
--------- | ---控制器

所以我有继承继承的类PawnController类.ActorObject

问题是我需要Controller在pawn类和Pawn控制器类中的实例中引用.
因此我向前宣布PawnControllerActor.h:

// Actor.h

// (...) Actor Declaration (...)

class Pawn;
class Controller;
Run Code Online (Sandbox Code Playgroud)

然后在Pawn.h:

// Pawn.h

class Pawn : public Actor
{
private:
    Controller* controller;
public:
    void DoSomethingWithController(void);
}
Run Code Online (Sandbox Code Playgroud)

这一切都很好,没有错误.问题是当我想访问该类中的成员时:

void Pawn::DoSomethingWithController(void)
{
    // this->controller-> can't access members like this (members not found)
}
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么做才能在Pawn中有一个Controller指针和一个指向我的Controller中的Pawn的指针,将它们保存在不同的文件(.h和.cpp)中,同时能够访问它的成员?

感谢您的时间.:d

[如果需要更多信息,我会提供]

kle*_*ent 5

前向声明对编译器说,将进一步提供给定类型.编译器没有关于该类型的字段或成员的线索.因此,您需要在.cpp文件中包含相应的.h文件(您访问"controller"类成员的位置).