我的#include依赖项似乎阻止了我使用类
My #include dependencies seem to be preventing me from using a class
我试图使用另一个类中的函数,但我的依赖关系似乎阻止了我。
main.cpp
#include "gesture.hpp"
#include "statemachine.hpp"
Gesture g;
StateMachine sm(g);
手势.hpp
#include "hand.hpp"
状态机.hpp
#include "gesture.hpp"
StateMachine(Gesture&);
Gesture *g;
我正在努力实现的目标:我正在尝试使用已声明的StateMachine sm
中的一个函数。这个函数将在gesture.cpp
中的函数内部调用,我将给Gesture g
类一个指向StateMachine sm
的指针。(我会在主声明sm
之后这样做)我可以在gesture.cpp
文件中使用#include "statemachine.hpp"
,但我想将其移动到gesture.hpp
,这样我就可以将其作为指针存储在该类中作为变量。
所以当我这样做的时候手势.hpp
#include "hand.hpp"
#include "statemachine.hpp"
我得到错误'Gesture' does not name a type
和expected ')' before '&' token StateMachine(Gesture&);
有人能搞清楚发生了什么事吗?我无法将函数移动到gesture.cpp
,因为它使用了存储在我的statemachine.hpp
中的数组
您没有提供详细信息,所以我将在这里发布我的猜测。当预编译器分析"手势.hpp"时,它会将其展开为如下内容:
codes in hand.hpp
StateMachine(Gesture&);
Gesture *g;
statemachine.hpp中没有展开文件"姿态.hpp",因为我认为您已经提供了一些防止循环依赖的保护。所以编译器不知道手势是什么。
为了解决编译错误,您可以向statemachine.hpp提交一个手势的正向声明,如下所示:
class Gesture;
StateMachine(Gesture&);
Gesture *g;
相关文章:
- 如何从C++中的依赖类型中获得它所依赖的类型
- 既然存在危险,为什么项目要使用-I include开关
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何将更多文件夹添加到c++include路径
- 什么是"#include <boost/functional/hash.hpp> "?
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 将依赖名称显式标记为类型名和模板的奇怪之处
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- C++GTKMM gui循环依赖关系
- 通过ccmake在cmake中缓存依赖选项
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 当基类是依赖类型时,这是一个缺陷吗
- C++包含来自 #include "DevEngine/Core.h" 的错误
- 从不同的附加依赖项中识别等同命名的函数
- <filesystem> 在 clang 6 和 10 上 #include 错误
- 如何在 CMake 中对目标依赖项进行分组?
- 在 void 函数中使用 #include 变量C++
- 我可以创建一个链接另一个库但不依赖于其include的c++库吗
- #include 循环依赖项错误
- 我的#include依赖项似乎阻止了我使用类