C++ forward declaration error -
i have error goes this
in file included level.hpp:12, main.cpp:4: corridor.hpp: in method `void game::corridor::update()': corridor.hpp:41: invalid use of undefined type `class game::level' corridor.hpp:13: forward declaration of `class game::level' corridor.hpp:42: invalid use of undefined type `class game::level' corridor.hpp:13: forward declaration of `class game::level' corridor.hpp:43: invalid use of undefined type `class game::level' corridor.hpp:13: forward declaration of `class game::level' corridor.hpp:44: invalid use of undefined type `class game::level' corridor.hpp:13: forward declaration of `class game::level'
corridor , level ...
// corridor.hpp #ifndef game_corridor_hpp #define game_corridor_hpp #include <moot/math.hpp> //#include <level.hpp> #include <gamewindow.hpp> namespace game { class level; // <-- line 13 class corridor { static const unsigned int defaultleveldepth = 800; moot::math::vector3d wp1, wp2, wp3, wp4; moot::math::vector2d sp1, sp2, sp3, sp4; level * p_level; public: corridor(moot::math::vector3d setfirstpoint, moot::math::vector3d setsecondpoint) { wp1 = setfirstpoint; wp2 = setsecondpoint; wp3 = setfirstpoint; wp3.z += defaultleveldepth; wp4 = setsecondpoint; wp4.z += defaultleveldepth; } void update() { sp1 = p_level->getlevelcamera().convert3dvectorwithscreenalgorithm(wp1); // <- line 41 etc. sp2 = p_level->getlevelcamera().convert3dvectorwithscreenalgorithm(wp2); sp3 = p_level->getlevelcamera().convert3dvectorwithscreenalgorithm(wp3); sp4 = p_level->getlevelcamera().convert3dvectorwithscreenalgorithm(wp4); //p_level->getlevelcamera(); } void draw()//const { moot::color tempcolor; windowinstance().graphics().drawquad( sp1.x, sp1.y, tempcolor, sp2.x,sp2.y, tempcolor, sp3.x, sp3.y, tempcolor, sp4.x,sp4.y, tempcolor, 1); } void setlevel(level* setlevel) { p_level = setlevel; } }; } #endif
and
// level.hpp #ifndef game_level_hpp #define game_level_hpp #include <moot/forward.hpp> #include <moot/window.hpp> #include <moot/math.hpp> #include <gamewindow.hpp> #include <camera.hpp> #include <corridor.hpp> #include <player.hpp> #include <vector> namespace game { class level { typedef corridor* p_corridor; typedef std::vector<p_corridor> corridorlist; typedef corridorlist::reverse_iterator reversecorridoritter; corridorlist m_map; camera m_camera; player m_player; public: level() { m_player.setlevel(this); // lots of vertices being defined m_map. // loop through , set camera reversecorridoritter rit; for(rit = m_map.rbegin(); rit != m_map.rend(); rit++) (*rit)->setlevel(this); } ~level() { reversecorridoritter rit; for(rit = m_map.rbegin(); rit != m_map.rend(); rit++) delete (*rit); m_map.clear(); } void update() { // temp delete when input , player implimented. if(pad[0].buttons & pad_up) m_camera.updatetargetoffsets(0, -2); if(pad[0].buttons & pad_down) m_camera.updatetargetoffsets(0, 2); if(pad[0].buttons & pad_left) m_camera.updatetargetoffsets(-2, 0); if(pad[0].buttons & pad_right) m_camera.updatetargetoffsets(2, 0); m_player.update(); reversecorridoritter rit; (rit = m_map.rbegin(); rit != m_map.rend(); rit++) (*rit)->update(); } void draw() // const // eh!!! wtf reverseiter isn't member { m_player.draw(); reversecorridoritter rit; (rit = m_map.rbegin(); rit != m_map.rend(); rit++) (*rit)->draw(); } camera& getlevelcamera() { return m_camera; } }; } #endif
the pointer being set far can tell, when try access function level, boom!
thanks.
ps: compiler gcc 2.95.2 if makes difference.
edit
updated complete code.
you #include
-ing level
's complete declaration:
#include <level.hpp>
...and then try forward-declare level
:
namespace game { class level;
don't this. choose 1 or other. (edit) or @ least put forward-declaration before #include
-ion of complete declaration. if you're doing in game_corridor.hpp
setting pointers level
, forward declare should fine. if need call functions on level
within hpp file, you'll need #include
complete declaration.
edit2:
based on clarifying edit op, must #include
complete declaration of level
, , not try use forward declaration.
Comments
Post a Comment