问题描述
我有两个头文件,animation.h
和 hero.h
,
这是 animation.h
的代码:
#include <SFML/Graphics.hpp>
#include <iostream>
#include "hero.h"
#ifndef ANIMATION
#define ANIMATION
//Class
#endif
对于hero.h
:
#include <SFML/Graphics.hpp>
#include <iostream>
#include "animation.h"
#ifndef HERO
#define HERO
//Class
#endif
即使使用包含保护,我也收到错误消息 #include file "" includes itself
。
我刚开始使用包含守卫等,所以这可能是一个非常微不足道的错误。
感谢您的帮助
解决方法
你应该把头卫放在其他任何东西之前。
在 gcc
和 MSC
上,您也可以使用
#pragma once
相反。可能也在其他更现代的编译器上。只需将它放在包含的顶部,而不是 #ifdef...
。
animation.h
#ifndef ANIMATION
#define ANIMATION
#include <SFML/Graphics.hpp>
#include <iostream>
#include "hero.h"
//Class
#endif
hero.h
#ifndef HERO
#define HERO
#include <SFML/Graphics.hpp>
#include <iostream>
#include "animation.h"
//Class
#endif
或animation.h
#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
#include "hero.h"
//Class