为什么我不能从同一目录中的另一个文件中 #include 我的类?
Why can I not #include my class from another file in the same directory?
我有三个文件,结构如下
- src/
- events
- ...
- Event.cpp
- Event.h
- EventPtr.h
- ...
问题是EventPtr.h
内部的#include Event.h
似乎不起作用。这是代码:
事件.h
#ifndef POKERSIMULATIONSINCPP_EVENT_H
#define POKERSIMULATIONSINCPP_EVENT_H
#include <iostream>
#include "game/Table.h"
#include "players/Player.h"
namespace events {
enum TargetType {
Dealer, Table, None, Players
};
class Event {
private:
TargetType target = None;
std::string description = "Base event class";
bool done = false;
public:
~Event();
Event();
TargetType getTarget();
std::string getDescription();
bool getDone();
};
}
#endif //POKERSIMULATIONSINCPP_EVENT_H
事件.cpp
#include "Event.h"
#include <iostream>
namespace events {
TargetType Event::getTarget() {
return target;
}
std::string Event::getDescription() {
return description;
}
bool Event::getDone() {
return done;
}
Event::~Event() = default;
Event::Event() = default;
}
事件Ptr.h
#ifndef POKERSIMULATIONSINCPP_EVENTPTR_H
#define POKERSIMULATIONSINCPP_EVENTPTR_H
#include <memory>
#include "events/Event.h"
namespace events {
typedef std::shared_ptr<Event> EventPtr;
}
#endif //POKERSIMULATIONSINCPP_EVENTPTR_H
这给出了以下错误:
错误
D:/PokerSimulationsInCpp/src/events/EventPtr.h:13:29: error: 'Event' was not declared in this scope
typedef std::shared_ptr<Event> EventPtr;
我也尝试过这个EventPtr.h
EventPtr.h,第二次尝试
#ifndef POKERSIMULATIONSINCPP_EVENTPTR_H
#define POKERSIMULATIONSINCPP_EVENTPTR_H
#include <memory>
#include "events/Event.h"
#include "Event.h"
namespace events {
typedef std::shared_ptr<events::Event> EventPtr;
}
#endif //POKERSIMULATIONSINCPP_EVENTPTR_H
这给出了以下错误:
D:/PokerSimulationsInCpp/src/events/EventPtr.h:14:37: error: 'Event' is not a member of 'events'
typedef std::shared_ptr<events::Event> EventPtr;
有人知道发生了什么吗?
可能你有一个循环包含依赖项。
请检查 事件.h 包含的文件。如果您发现包含 EventPtr.h,这可能是错误。
我给你留下一个维基百科链接:循环依赖
相关文章:
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 如何从另一个文件继承私有成员变量和公共函数
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 如何在安卓工作室中将c ++头文件从一个文件夹导入到另一个文件夹?
- 使用 scope 运算符 (::) 引用另一个文件中的类
- JNI,使用两个 .so 文件时出错,其中一个文件需要另一个文件
- 为什么我不能从同一目录中的另一个文件中 #include 我的类?
- 在 c++ 中打开文件、删除标点符号并追加到另一个文件中
- C++ 如何将两个 makefile 对象目标规则(位于另一个文件夹中)合并到一个目标/规则中?
- 是否可以将子进程的 stdout 重定向到父进程中的另一个文件?
- 如何在标准c ++中流式传输/读取二进制文件的中间部分并写入另一个文件?
- 如何从另一个文件调用类构造函数?
- 包含来自另一个文件的函数会导致范围错误(openFoam)
- 从类中的另一个文件请求函数不起作用
- 从文件中读取成绩并将平均值输出到另一个文件C++
- 包括来自另一个文件的运算符重载
- C++-更改另一个文件的ASM指令
- 如何让 + 重载在另一个文件C++中被识别?
- 引用另一个文件夹中的.dll