C++包括多个文件中的文件

1 c++ inheritance include c-preprocessor

我试图在C++中将某个类继承到两个子类中.我希望子类并行运行,但它们都继承了超类entity.hpp:

#include "../entity.hpp"
class Npc : public Entity
{}

#include "../entity.hpp"
class Human : public Entity
{}
Run Code Online (Sandbox Code Playgroud)

当然,当我这样做的时候

#include "Npc.hpp"

#include "Human.hpp"

在同一个文件中,我遇到了一个问题因为entity.hpp包含两次.我怎么能绕过这个?

编辑:.cpp文件是一个错字.

Luc*_*ore 6

无论是使用包括在你的头警卫,或#pragma once指令(这是不一样的广泛支持).