I'm new to C++, in order to learn it better (I learn from doing) I have rewritten the code from an example C++ game I found over on GitHub, I intend to alter pieces of code to expand on it and change the graphics once I have it working in order to know exactly what does what. Rather than simply copying and pasting the existing code I made sure to write it all myself, I believe re-writing code gives a better understanding than simply copy&paste.
I'm trying to load images for a small game as a C++ test, when trying to execute the code from the IDE it keeps failing near if(iter == _images.end()) I have tried everything I myself can think of like changing the type of _images, changing how filename gets made, adding checks, removing checks, I have spent the last 3 days on Google and StackOverflow trying every fix I came accross that mentioned a similar problem. So far nothing has helped.
I will post the code sections I believe relevant to this here, please have a look and point me to where or how to fix this.
First things first, the error it shows me:
Exception thrown: read access violation.
std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,sf::Texture,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,sf::Texture> >,0> >::_Root(...) returned 0x4.
If there is a handler for this exception, the program may be safely continued.
From what I have gathered this has to do with the memory it is trying to read/write to.
Call Stack
FileName.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,sf::Texture,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,sf::Texture> >,0> >::_Lbound<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Keyval) Line 2060 C++
FileName.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,sf::Texture,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,sf::Texture> >,0> >::lower_bound(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Keyval) Line 1538 C++
FileName.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,sf::Texture,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,sf::Texture> >,0> >::find(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Keyval) Line 1481 C++
FileName.exe!VisibleGameObject::Load(std::basic_string<char,std::char_traits<char>,std::allocator<char> > filename) Line 17 C++
FileName.exe!Player::Player() Line 7 C++
FileName.exe!`dynamic initializer for 'speler''() Line 30 C++
[External Code]
VisibleGameObject.cpp
void VisibleGameObject::Load(std::string filename) {
filename = "textures/" + filename;
//Basic algorithm for images
auto iter = _images.find(filename);
if (iter == _images.end()) {
sf::Texture texture;
if (!texture.loadFromFile(filename)) {
std::cout << "[ERROR] Image failed to load!" << std::endl;
assert(false);
}
auto img = _images.insert(std::pair<std::string, sf::Texture>(filename, texture)).first;
std::cout << "[DEBUG] " + filename + ": Loaded and added to cache." << std::endl;
_sprite.setTexture(img->second);
_isLoaded = true;
}
else {
_sprite.setTexture(iter->second);
_isLoaded = true;
}
_imageKey = filename;
}
VisibleGameObject.h
#pragma once
#include "stdafx.h"
class VisibleGameObject {
public:
VisibleGameObject();
virtual ~VisibleGameObject();
virtual void Load(std::string filename);
virtual void Draw(sf::RenderWindow & window);
virtual void Update(float elapsedTime) = 0;
virtual void SetPosition(float x, float y);
virtual sf::Vector2f GetPosition() const;
virtual float GetWidth() const;
virtual float GetHeight() const;
virtual sf::Rect<float> GetBoundingRect() const;
virtual bool IsLoaded() const;
virtual bool ShouldPersist() const;
virtual void ToggleVisibility(bool isVisible);
virtual bool ShouldDraw() const;
protected:
sf::Sprite& GetSprite();
private:
sf::Sprite _sprite;
std::string _imageKey;
bool _isLoaded;
bool _shouldDraw;
static std::map<std::string, sf::Texture> _images;
};
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <map>
#include <iostream>
#include <cassert>
The call to VisibleGameObject.cpp happens from Game.cpp
void Game::Start() {
_mainWindow.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Window PlaceHolder Title");
Background *background1 = new Background(1);
background1->SetPosition(0.f, -768.f);
_gameObjectManager.Add("bg1", background1);
Background *background2 = new Background(2);
background2->SetPosition(0.f, -768.f);
_gameObjectManager.Add("bg2", background2);
Background *background4 = new Background(4);
background4->SetPosition(0.f, -768.f);
_gameObjectManager.Add("bg4", background4);
Player *player = new Player();
player->ResetStartingPosition();
_gameObjectManager.Add("player", player);
MainHUD *hud = new MainHUD();
_gameObjectManager.Add("hud", hud);
GameOverHUD *gameOver = new GameOverHUD();
_gameObjectManager.Add("gameover", gameOver);
while (!IsExiting()) {
GameLoop();
}
_mainWindow.close();
}
If anything is missing or I have added things that can be exluded, let me know and I will edit the question.
Related
I am using an SFML view integrated inside a wxWidgets frame. I used the code sample on the SFML website (which is quite old but I got it to work making a few tweaks) to do this. And then started fleshing out my project from that base class. However, I am at the stage now where I need to create and delete many SFML+wxWidgets windows based on user actions, however SFML crashes whenever I close its parent wxWidgets window.
I get the following error:
Cannot close SFML area when SFML is integrated in a NSView.
All the SFML+wxWidgets examples on the web I found face this error when I run it after closing. This error should not be an issue if the user only needs to close the window once, but I am managing many windows over the user session, so if it crashes once, it brings down the whole app with it.
Here is the section of the header file code for the base class combining wxWidgets and sfml, everything else is specific to my app, and not to the error:
class ChessWidgetBase : public wxControl, public sf::RenderWindow {
public:
ChessWidgetBase(wxWindow* parent, wxSize size);
virtual ~ChessWidgetBase() {};
private:
DECLARE_EVENT_TABLE()
virtual void HandleLeftDown(wxMouseEvent&) {}
virtual void HandleLeftUp(wxMouseEvent&) {}
virtual void OnUpdate() {};
void OnIdle(wxIdleEvent&);
void OnPaint(wxPaintEvent&);
void OnEraseBackground(wxEraseEvent&);
};
This code is based off this minimum reproducable example I used from the internet to make the above class:
#include <iostream>
#include <wx/wx.h>
#include <memory>
#include <SFML/Graphics.hpp>
#ifdef __WXGTK__
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#endif
using namespace std;
static const int kDefaultWindowWidth = 1280;
static const int kDefaultWindowHeight = 720;
static const int kCanvasMargin = 50;
struct wxSfmlCanvas : public wxControl, public sf::RenderWindow
{
wxSfmlCanvas(
wxWindow *parent = nullptr,
wxWindowID windowId = -1,
const wxPoint &position = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0) :
wxControl(parent, windowId, position, size, style)
{
createRenderWindow();
}
virtual void onUpdate(){};
void onIdle(wxIdleEvent& event)
{
// Send a paint message when control is idle, to ensure max framerate
Refresh();
}
void onPaint(wxPaintEvent& event)
{
wxPaintDC dc(this); // Prepare control to be repainted
onUpdate(); // Tick update
display(); // Draw
}
// Explicitly overriding prevents wxWidgets from drawing, which could result in flicker
void onEraseBackground(wxEraseEvent& event){}
void createRenderWindow()
{
#ifdef __WXGTK__
gtk_widget_realize(m_wxwindow);
gtk_widget_set_double_buffered(m_wxwindow, false);
GdkWindow *gdkWindow = gtk_widget_get_window((GtkWidget*)GetHandle());
XFlush(GDK_WINDOW_XDISPLAY(gdkWindow));
sf::RenderWindow::create(GDK_WINDOW_XWINDOW(gdkWindow));
#else
sf::RenderWindow::create(GetHandle());
#endif
}
void setwxWindowSize(const wxSize& size)
{
this->SetSize(size);
}
void setRenderWindowSize(const sf::Vector2u& size)
{
this->setSize(size);
}
virtual ~wxSfmlCanvas(){};
wxDECLARE_EVENT_TABLE();
};
struct Canvas : public wxSfmlCanvas
{
Canvas(
wxWindow* parent,
wxWindowID id,
wxPoint position,
wxSize size,
long style = 0) :
wxSfmlCanvas(parent, id, position, size, style)
{
}
virtual void onUpdate()
{
clear(sf::Color::Yellow);
// TODO: Do some sprite drawing or whatever
}
void onResize(wxSizeEvent& event)
{
auto size = event.GetSize();
auto newCanvasWidth = size.x - (2 * kCanvasMargin);
auto newCanvasHeight = size.y - (2 * kCanvasMargin);
// Resize Canvas window
this->setwxWindowSize({newCanvasWidth, newCanvasHeight});
this->setRenderWindowSize({(unsigned int)newCanvasWidth, (unsigned int)newCanvasHeight});
}
};
struct AppFrame : public wxFrame
{
AppFrame(const wxString& title, const wxPoint& pos, const wxSize& size) :
wxFrame(NULL, wxID_ANY, title, pos, size),
_panel(new wxPanel(this)),
_canvas(new Canvas(
_panel.get(),
wxID_ANY,
wxPoint(kCanvasMargin, kCanvasMargin),
wxSize(kDefaultWindowWidth - (2 * kCanvasMargin), kDefaultWindowHeight - (2 * kCanvasMargin))
))
{
_panel->SetBackgroundColour(*wxCYAN);
////////////////////////////////////////////////////////////////////////////////
// Probably due to some RTTI, IDE is getting confused by this dynamic call
// and doesn't understand the correct Bind overload. Causes non sequitur errors
// to display in the inspector. Suppress.
//
// Dynamic binding is cleanest here, since we don't want to hook up our resize
// handler until our dependencies (Canvas namely) have finished their initialization
////////////////////////////////////////////////////////////////////////////////
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wint-conversion"
Bind(wxEVT_SIZE, &AppFrame::onResize, this);
#pragma clang diagnostic pop
////////////////////////////////////////////////////////////////////////////////
}
void onResize(wxSizeEvent& event)
{
_canvas->onResize(event);
event.Skip();
}
unique_ptr<wxPanel> _panel;
unique_ptr<Canvas> _canvas;
};
struct App : public wxApp
{
virtual bool OnInit()
{
auto frame = new AppFrame("SFML Canvas Demo", wxPoint(100, 100),
wxSize(kDefaultWindowWidth, kDefaultWindowHeight));
frame->Show(true);
return true;
}
};
wxBEGIN_EVENT_TABLE(wxSfmlCanvas, wxControl)
EVT_IDLE(wxSfmlCanvas::onIdle)
EVT_PAINT(wxSfmlCanvas::onPaint)
EVT_ERASE_BACKGROUND(wxSfmlCanvas::onEraseBackground)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(App);
(if you want to run it you might have to install sfml+wxwidgets)
Any ways to handle closing a window that prevents a crash with wxWidgets+SFML? Just need some ideas and a couple lines of code to show them, no need for complete examples...
To fix this error upgrade SFML to version >= 2.6.0. You cannot find this in the downloads site for SFML as it hasn't been released yet, so you must install from the Github directly over here and build it from source: https://github.com/SFML/SFML/tree/2.6.x.
I am using SFML to create a space invaders clone with C++. I am quite new to C++ and I'm learning it as I'm working on this project.
I am getting the following error when trying to create a new enemy using the constructor and array to set settings for each created enemy:
1>enemy.cpp
1>C:\Users\dzamm\source\repos\SFML\enemy.cpp(35,1): error C2280: 'Enemy &Enemy::operator =(const Enemy &)': attempting to reference a deleted function
1>C:\Users\dzamm\source\repos\SFML\enemy.h(55): message : compiler has generated 'Enemy::operator =' here
1>C:\Users\dzamm\source\repos\SFML\enemy.h(55,1): message : 'Enemy &Enemy::operator =(const Enemy &)': function was implicitly deleted because a data member invokes a deleted or inaccessible function 'sf::RenderWindow &sf::RenderWindow::operator =(const sf::RenderWindow &)'
Enemy Constructor:
Enemy alienArray[NUMBER_OF_ALIENS];
//constructor sets ID number, loads sprite
Enemy::Enemy(const int id, float sp)
{
//set alive
mIsAlive = true;
//set speed
enemySpeed = sp;
// Load an enemy texture
if (!mEnemyTexture.loadFromFile("Media/Textures/PixelSpaceships/red_01.png")) {
// Handle loading error
std::cout << "Oh No! File not loaded." << std::endl;
}
//scale sprite and set texture so we know size
enemySprite.setTexture(mEnemyTexture);
}
Enemy loader method
void Enemy::loader(int noOfAliens) { // might add xPosition;yPosition
for (int i = 0; i < noOfAliens; i++)
{
Enemy alien(i, 10.f); // speed issue
alien.setLocation(i * 100.f + 50.f, alien.getSprite().getGlobalBounds().height / 2);
line 35 alienArray[i] = alien;
//alienArray.push_back(alien);
}
}
1>C:\Users\dzamm\source\repos\SFML\enemy.cpp(35,1): error C2280: 'Enemy &Enemy::operator =(const Enemy &)': attempting to reference a deleted function
Enemy Header file:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#pragma once
#define NUMBER_OF_ALIENS 4
//class Game;
class Enemy
{
public:
//constructor sets ID number, loads sprite
Enemy() {};
Enemy(const int, float);
sf::Sprite& getSprite();
void kill();
bool isAlive();
void load();
void loader(const int noOfAliens);
void setLocation(float xPosition, float yPosition);
void enemyInstantiator(int noOfEnemies, float xPosition, float yPosition);
void update();
void render(sf::RenderWindow& window);
private:
void enemyBehaviour(std::vector<sf::Sprite>& enemyList);
void enemyMovement(std::vector<Enemy>& enemyList);
private:
sf::Texture mEnemyTexture;
sf::Sprite enemySprite;
//std::vector<Enemy> alienArray;
//std::vector<sf::Sprite> mEnemies;
sf::RectangleShape mEnemyBounds;
sf::RenderWindow mWindow;
bool mIsShooting;
bool mIsAlive;
float enemySpeed;
};
I read on forums that issue is related to working with a copy of the object instead of the original object, however I am not sure how to handle this to reference the original object I'm modifying.
To reproduce create a constructor for Enemy.cpp class, create an entity Enemy alien using for loop in method as shown in Enemy::loader and store the created entity in the Enemy alienArray as shown by index.
The issue was related to an sf::RenderWindow reference that was not being even utilised in the code.
sf::RenderWindow &sf::RenderWindow::operator =(const sf::RenderWindow &)
Once I removed this all errors disappeared.
I have seen this question: "Class type redefinition" error between header and source files
If you'll just say a duplicate of the above question, please check first the code below.
The problem is that the "Class type redefinition" should not happened because I think I have done it properly.
Here is the code.
TTSpeech.h
#include <wtypes.h>
#include <string>
#include <vector>
class TTSpeech
{
public:
enum State
{
State_Loaded,
State_Unloaded,
};
TTSpeech();
virtual ~TTSpeech();
virtual bool isAvailable() = 0;
virtual bool load() = 0;
virtual bool unload() = 0;
virtual bool isLoaded() const = 0;
virtual bool say(const std::string &sentence) = 0;
virtual bool setVolume(int volume) = 0;
virtual bool setPitch(int pitch) = 0;
virtual bool setRate(int rate) = 0;
virtual bool setVoice(const std::string &voice) = 0;
virtual std::vector<std::string> getVoices() const = 0;
};
TTSpeech.cpp
#include "TTSpeech.h"
TTSpeech::TTSpeech()
{
//code
}
TTSpeech::~TTSpeech()
{
//code
}
The only unusual thing that I have done is to remove the files from the solution, relocate the above file to a folder because of this issue: cannot open include no such file or directory. Then re-add the files to the solution. I'm using Visual Studio 2012 running of Windows 8
I have many .cpp files in my project that work. But this one irritates Xcode or the compiler.
It doesn't recognise free() and malloc() but this is also C. What can be wrong?
Header ssdpmessage.h looks like this:
#ifndef _SSDPMESSAGE_H
#define _SSDPMESSAGE_H
#include "ssdptools.h"
#include <vector>
#include <arpa/inet.h>
#include "ssdpdb.h"
class SSDPMessage{
public:
SSDPMessage();
virtual ~SSDPMessage();
//What type of message can we handle
virtual SSDP_TYPE GetType()=0;
//Get the message dignature implemented in this class
virtual std::vector<SSDP_HTTP_HEADER*> GetHeaderSignature();
//Can this class parse the message with this signature ?
virtual u8 CanProcess(std::vector<SSDP_HTTP_HEADER*> msgheaders);
//Process the message, return value:
//0 : processed
//1 : not for me, search for another to process
//<0 : message was for me but there is an error
virtual int Process(struct sockaddr* sender, std::vector<SSDP_HTTP_HEADER*> msgheaders)=0;
//ReInit all members
virtual void ReInit()=0;
virtual SSDPDB* GetDB();
virtual void SetDB(SSDPDB* db);
private:
std::vector<SSDP_HTTP_HEADER*> mHeaderSignature;
protected:
int AddSignatureHeader(char* fieldname, char* fieldvalue);
SSDPDB *mDB;
private:
SSDPMessage(const SSDPMessage &src);
SSDPMessage& operator= (const SSDPMessage &src);
};
#endif //_SSDPMESSAGE_H
The includes and affected code in ssdpmessage.cpp look like this:
#include "ssdpmessage.h"
SSDPMessage::SSDPMessage():mDB(NULL){
}
SSDPMessage::~SSDPMessage(){
std::vector<SSDP_HTTP_HEADER*>::iterator it;
for(it=mHeaderSignature.begin(); it<mHeaderSignature.end(); it++){
free(*it);
}
mHeaderSignature.clear();
}
int SSDPMessage::AddSignatureHeader(char* fieldname, char* fieldvalue){
SSDP_HTTP_HEADER *thisHeader = (SSDP_HTTP_HEADER*)malloc(sizeof(SSDP_HTTP_HEADER));
thisHeader->fieldname = (u8*)fieldname;
thisHeader->fieldnamelen = strlen(fieldname);
thisHeader->fieldvalue = (u8*)fieldvalue;
thisHeader->fieldvaluelen = strlen(fieldvalue);
mHeaderSignature.push_back(thisHeader);
return mHeaderSignature.size();
}
This is code from the upnpx library. It works without problem in the demo project of the library.
malloc requires you to include cstdlib.
I have an error that goes like this
In file included from Level.hpp:12,
from 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 and Level are ...
// 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 into m_map.
// Loop through and 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 and player are 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;
for (rit = m_map.rbegin(); rit != m_map.rend(); rit++)
(*rit)->update();
}
void draw() // const // EH!!! wtf ReverseIter isn't a member
{
m_player.draw();
ReverseCorridorItter rit;
for (rit = m_map.rbegin(); rit != m_map.rend(); rit++)
(*rit)->draw();
}
Camera& getLevelCamera() {
return m_camera;
}
};
}
#endif
The pointer is being set as far as I can tell, but when I try to access a function from Level, BOOM!
Thanks.
PS: The compiler is gcc 2.95.2 if that makes a difference.
EDIT
Updated with complete code.
You are #include-ing Level's complete declaration:
#include <Level.hpp>
...and then you try to forward-declare Level:
namespace Game
{
class Level;
Don't do this. Choose one or the other. (edit) Or at least put the forward-declaration before the #include-ion of the complete declaration. If all you're doing in game_corridor.hpp is setting pointers to a Level, then a forward declare should do fine. If however you need to call functions on Level from within the HPP file, then you'll need to #include the complete declaration.
EDIT2:
Based on your clarifying edit to your OP, you must #include the complete declaration of Level, and not try to use a forward declaration.
If you forward-declare Game::Level then don't #include it. In a not-so-related note, use #include "header.hpp", not #include <header.hpp>.
Edit as per your updates: Bring the definition of Game::Corridor::update() outside the header and into an implementation file. This way the compile need not know anything about Game::Level apart from the fact that it exists and it's a type.
The problem is that Corridor doesn't know what a Level is, because it can't really #include Level.hpp, because Level.hpp is what #included Corridor.hpp.
The underlying problem is that you're trying to #include a source file. The really underlying problem is that you're using #include when you haven't separated your code into source files and header files. Here's how to split it up. (I'm assuming you're familiar with compiling source files into object files, then linking them into executables.)
Corridor.hpp:
#ifndef GAME_CORRIDOR_HPP
#define GAME_CORRIDOR_HPP
#include <Moot/Math.hpp>
#include <Level.hpp>
namespace Game
{
class Level;
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);
void update();
void draw();
void setLevel(Level* setLevel);
};
}
#endif
Corridor.cpp:
#include "Corridor.hpp"
namespace Game
{
Corridor::Corridor(Moot::Math::Vector3D setFirstPoint, Moot::Math::Vector3D setSecondPoint)
{
wp1 = setFirstPoint;
wp2 = setSecondPoint;
wp3 = setFirstPoint;
wp3.z += defaultLevelDepth;
wp4 = setSecondPoint;
wp4.z += defaultLevelDepth;
}
void Corridor::update()
{
sp1 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp1);
sp2 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp2);
sp3 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp3);
sp4 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp4);
}
// and so on
}