命名空间内类的循环依赖问题
Cyclic Dependency Issue with Class inside Namespace
我遇到了循环依赖问题。我有两个头文件,它们各自相互依赖。我遇到的问题与命名空间中的类有关。
文件 #1
class Player; // This is how I forward declare another class
namespace sef {
class Base
{
public:
Player a;
bool SendEvent(int eventType);
};
class Sub: public Base
{
protected:
Player b;
bool Execute(string a);
};
}
文件 #2
//class sef::Sub; // I am having trouble compiling this
class Player
{
public:
sef::Sub* engine; // I am having trouble compiling this
};
如何在文件 #2 中转发声明 sef::Sub 类?
首先,如果只声明类型,则只能使用指针或引用。
class Player; // declaration, not definition
class Base {
Player* p;
};
其次,命名空间是可扩展的,因此您可以编写如下:
namespace Foo { class Player; }
并使用指针:
class Base {
Foo::Player* p;
}
相关文章:
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 在包含窗口标头时难以解决循环依赖关系问题
- C++ 中的循环依赖关系问题
- 交叉依赖项类的问题
- "std::shared_ptr"循环依赖关系是如何导致问题的
- 生成的依赖项问题
- C++ API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL依赖项问题
- 是库依赖问题可以通过接口避免
- 另一个模板循环依赖问题
- 命名空间内类的循环依赖问题
- 交叉编译助推 1.60.0 内部依赖问题
- 使用发布 CRT 在调试中构建应用程序,并在提升时存在依赖问题
- 循环依赖问题
- 循环依赖问题
- c++:循环依赖问题
- c++ -构建顺序和依赖问题
- brew install glew 没有解决我的 <GL/glew.h>依赖问题
- 你能用C++解决这个循环依赖问题吗
- 类的相互依赖问题
- 在使用模板时避免循环依赖问题