0
嗨,大家我有兩個類都需要另一個包括,我試圖包括在Ah文件中的B類頭和Bh文件中的類A頭,但我得到錯誤,由於圓形包括一些研究後,我發現,被稱爲提前聲明的解決方案,但對我來說不是工作,這是我的實際情況:C++/Cli循環包含
// 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
這是的GraphicsDevice類:
// 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
}
}
}
有人能請幫幫我?我變得瘋狂的xD
解決
我已經解決了更換引用類遊戲;與命名空間BSGameFramework {ref類遊戲; }
前向聲明是什麼意思「不起作用?」你是否收到任何錯誤訊息? –
代碼中還有另一個名稱爲「Game」的標識符。我們看不到它。 –
請仔細閱讀最後,我已對該代碼發表評論! – ThomasSquall