我正面臨使用前向聲明的問題,我不知道如何解決它。這裏是我的文件:使用前向聲明編譯時間「null」?
BubblePlug.h
#ifndef _BUBBLEPLUG_
#define _BUBBLEPLUG_
#include "IPlug_include_in_plug_hdr.h"
#include "resource.h"
#include "IControl.h"
class IPianoRoll;
class IMidiEngine;
class BubblePlug: public IPlug
{
private:
public:
IMidiEngine *pMidiEngine;
IPianoRoll *pPianoRoll;
BubblePlug(IPlugInstanceInfo instanceInfo);
~BubblePlug();
};
#endif // !_BUBBLEPLUG_
BubblePlug.cpp
#include "BubblePlug.h"
#include "IPlug_include_in_plug_src.h"
#include "IPianoRoll.h"
#include "IMidiEngine.h"
BubblePlug::BubblePlug(IPlugInstanceInfo instanceInfo) : IPLUG_CTOR(10, 1, instanceInfo) {
pPianoRoll = new IPianoRoll(this, 8, 8);
pMidiEngine = new IMidiEngine(this);
}
BubblePlug::~BubblePlug() {
delete pPianoRoll;
delete pMidiEngine;
}
IPianoRoll.h
#ifndef _IPIANOROLL_
#define _IPIANOROLL_
#include "IMidiEngine.h"
class IPianoRoll : public IControl
{
private:
BubblePlug *pBubblePlug;
public:
IPianoRoll(BubblePlug *bubbleplug, int x, int y) : IControl(bubbleplug, IRECT(x, y, x + 10, y + 10)), pBubblePlug(bubbleplug) {
}
~IPianoRoll() {
};
bool Draw(IGraphics *pGraphics) {
return true;
}
void Random(bool onlyScore = false) {
pBubblePlug->pMidiEngine->Init();
}
void Start() {
}
};
#endif // !_IPIANOROLL_
IMidiEngine.h
#ifndef _IMIDIENGINE_
#define _IMIDIENGINE_
class IMidiEngine
{
private:
BubblePlug *pBubblePlug;
public:
IMidiEngine(BubblePlug *bubbleplug) : pBubblePlug(bubbleplug) {
}
~IMidiEngine() {
};
void Init(bool randomScore = true) {
pSamplwhk->pPianoRoll->Start();
}
};
#endif // !_IMIDIENGINE_
當我編譯,它說,圍繞pSamplwhk->pPianoRoll->Start();
:
use of undefined type 'IPianoRoll'
left of '->Start' must point to class/struct/union/generic type
VS2015找到每個元素編寫代碼(我沒有問題),它發生只有當我編譯(構建)。
爲什麼?我通過BubblePlug
,我做了IPianoRoll
和IMidiEngine
的轉發,包括他們的訂單(在BubblePlug.cpp
)。
IMidiEngine
應該知道關於IPianoRoll
(它首先包括在內)的一切。
至少,我應該在「運行時」有問題,爲什麼在編譯?
你能幫我理解問題以及如何解決它嗎?謝謝。
嘗試添加'#include「IMidiEngine.h」'到IPianoRoll.h – alexeykuzmin0
@ alexeykuzmin0:我編輯了這個問題。一探究竟! – markzzz
無關:你的包括警衛是非法的。 https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier –