私はフォワード宣言を使用している問題に直面しており、それを修正する方法はわかりません。ここに私のファイルです:フォワード宣言を使用してコンパイル時に "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_
I はをコンパイルし、それが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
(これが最初に含まれています)を知っている必要があります。
少なくとも、「実行時」に問題があるはずです。なぜコンパイルするのですか?
問題を理解し、解決する方法を教えていただけますか?ありがとう。
IPianoRoll.hに '#include" IMidiEngine.h "を追加してみてください – alexeykuzmin0
@ alexeykuzmin0:私は質問を編集しました。見てみな! – markzzz
無関係:あなたのインクルードガードは違法です。 https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier –