我试图将某个类继承到 C++ 中的两个子类中。我希望子类并排运行,但它们都继承了父类(super class)entity.hpp
:
#include "../entity.hpp"
class Npc : public Entity
{}
#include "../entity.hpp"
class Human : public Entity
{}
当然,当我这样做的时候
#include "Npc.hpp"
#include "Human.hpp"
在同一个文件中,我遇到了一个问题,因为 entity.hpp
被包含了两次。我该如何解决这个问题?
编辑:.cpp 文件是错字。
最佳答案
要么在你的 header 中使用 include guards,要么使用 #pragma once
指令(没有得到广泛支持)。
关于C++ 在多个文件中包含一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13195944/