C++ 我的#include依赖项似乎阻止了我使用类

C++ 我的#include依赖项似乎阻止了我使用类,c++,dependencies,header-files,C++,Dependencies,Header Files,我试图使用另一个类中的函数,但我的依赖项似乎阻止了我 main.cpp #include "gesture.hpp" #include "statemachine.hpp" Gesture g; StateMachine sm(g); #include "hand.hpp" #include "gesture.hpp" StateMachine(Gesture&); Gesture *g; #include "hand.hpp" #include "statemachine.h

我试图使用另一个类中的函数,但我的依赖项似乎阻止了我

main.cpp

#include "gesture.hpp"
#include "statemachine.hpp"

Gesture g;
StateMachine sm(g);
#include "hand.hpp"
#include "gesture.hpp"

StateMachine(Gesture&);
Gesture *g;
#include "hand.hpp"
#include "statemachine.hpp"
手势.hpp

#include "gesture.hpp"
#include "statemachine.hpp"

Gesture g;
StateMachine sm(g);
#include "hand.hpp"
#include "gesture.hpp"

StateMachine(Gesture&);
Gesture *g;
#include "hand.hpp"
#include "statemachine.hpp"
状态机.hpp

#include "gesture.hpp"
#include "statemachine.hpp"

Gesture g;
StateMachine sm(g);
#include "hand.hpp"
#include "gesture.hpp"

StateMachine(Gesture&);
Gesture *g;
#include "hand.hpp"
#include "statemachine.hpp"

我正在努力实现的目标: 我试图使用我声明的
状态机sm
中的函数。此函数将在
sirtage.cpp中的函数内调用,我将为
sirtage g
类提供指向
StateMachine sm
的指针。(在我主要声明
sm
之后,我会这样做)我能够
#在我的
手势.cpp
文件中包含“statemachine.hpp”
,但我想将其移动到
手势.hpp
以便将其作为指针存储在该类中作为变量

所以当我这么做的时候 手势.hpp

#include "gesture.hpp"
#include "statemachine.hpp"

Gesture g;
StateMachine sm(g);
#include "hand.hpp"
#include "gesture.hpp"

StateMachine(Gesture&);
Gesture *g;
#include "hand.hpp"
#include "statemachine.hpp"
我得到一个错误,
“手势”没有在“&”标记状态机(手势&)之前命名类型
预期“)


有人知道发生了什么事吗?我无法将我的函数移动到
手势.cpp
,因为它使用了存储在我的
状态机.hpp

中的数组。您没有提供详细信息,因此我将在此处发布我的猜测。 当预编译器分析“手势.hpp”时,它会将其展开如下:

codes in hand.hpp
StateMachine(Gesture&);
Gesture *g;
class Gesture;
StateMachine(Gesture&);
Gesture *g;
文件“signature.hpp”没有在statemachine.hpp中展开,因为我认为您提供了一些防止循环依赖的保护。所以编译器不知道手势是什么

要解决编译错误,您可以向statemachine.hpp提出手势声明,如下所示:

codes in hand.hpp
StateMachine(Gesture&);
Gesture *g;
class Gesture;
StateMachine(Gesture&);
Gesture *g;

很难说可能是重复的,因为你没有提供足够的信息来确定,但我猜你需要一个转发声明。查找它。问题可能与循环依赖有关。如果
A.h需要B.h
B.h
需要
A.h
,则您遇到了问题。要解决此问题,必须使用前向声明,以便
A.h
包括
B.h
B.h
不包括
A.h
,而是前向声明在
A.h
中定义的类型。看一看:事实上,我注意到,
手势
在您声明的
手势.hpp
内容中没有声明或定义。这将很好地解释您的问题。感谢各位的回复,我已经声明了
signature()