SOLVED
I've solved replacing ref class Game; with namespace BSGameFramework { ref class Game; }
题
Hi everybody I have two classes that both need the other one included, I have tried to include in A.h file the class B header and in B.h file the class A header but I was getting errors due to the circular include, after some research I have found the solution that's called forward declaration but for me is not working, that's my actual situation:
// Game.h
#ifndef _GAME_H_
#define _GAME_H_
#ifndef _GRAPHICSDEVICE_H_
#include "GraphicsDevice.h"
#endif
using namespace BSGameFramework::Graphics;
namespace BSGameFramework
{
public ref class Game
{
public:
Game();
virtual ~Game();
property GraphicsDevice^ Device
{
GraphicsDevice^ get()
{
return device_;
}
}
// Other code here
private:
GraphicsDevice^ device_;
}
}
#endif
And this is the GraphicsDevice class:
// GraphicsDevice.h
#ifndef _GRAPHICSDEVICE_H_
#define _GRAPHICSDEVICE_H_
// forward declaration
ref class Game; // <-- this is giving me error C2872: 'Game' : ambiguous symbol
using namespace BSGameFramework;
namespace BSGameFramework
{
namespace Graphics
{
public ref class GraphicsDevice
{
public:
GraphicsDevice(); // I need to pass my Game class to the constructor
virtual ~GraphicsDevice();
// Here other code
}
}
}
Can somebody help me please? I'm becoming crazy xD
SOLVED
I've solved replacing ref class Game; with namespace BSGameFramework { ref class Game; }
解决方案
SOLVED
I've solved replacing ref class Game; with namespace BSGameFramework { ref class Game; }