我的问题很普遍,我知道,但我已经搜索和尝试了我找到的每个解决方案,但仍然不起作用。所以任何帮助将不胜感激!=)
提前致谢!
我在编译时遇到了这个错误:
g++ -ISFML/include -Iclasses/ -W -Wall -Werror -c -o classes/Object.o classes/Object.cpp
In file included from classes/Core.hh:18:0,
from classes/Object.hh:4,
from classes/Object.cpp:1:
classes/MapLink.hh:9:1: error: invalid use of incomplete type ‘struct Object’
classes/MapLink.hh:6:7: error: forward declaration of ‘struct Object’
In file included from classes/Core.hh:19:0,
from classes/Object.hh:4,
from classes/Object.cpp:1:
classes/Player.hh:9:1: error: invalid use of incomplete type ‘struct Object’
classes/MapLink.hh:6:7: error: forward declaration of ‘struct Object’
make: *** [classes/Object.o] Error 1
所以基本上,我有一个包含(main.cpp)的主要内容。
#include "Core.hh"
int main(void)
{
...
}
这是包含我所有头文件的头文件(Core.hh)。
#ifndef __CORE_HH__
# define __CORE_HH__
#include ...
#include "Object.hh"
#include "MapLink.hh"
#include "Player.hh"
class Core
{
...
};
#endif /* __CORE_HH__ */
然后是那些给我带来麻烦的文件(Object.hh)
#ifndef __OBJECT_HH__
# define __OBJECT_HH__
#include "Core.hh"
class Object
{
...
};
#endif /* __OBJECT_HH__ */
(MapLink.hh)
#ifndef __MAPLINK_H__
# define __MAPLINK_H__
#include "Core.hh"
class Object;
class MapLink : public Object
{
...
};
#endif /* __MAPLINK_H__ */
(Player.hh)
:(Player.hh)是一个头文件,可能与“玩家”有关。#ifndef __PLAYER_H__
# define __PLAYER_H__
#include "Core.hh"
class Object;
class Player : public Object
{
...
};
#endif /* __PLAYER_H__ */