2012-08-15 139 views
0

我在xcode中出現鏈接錯誤,我很難理解並發現問題。這是我得到的錯誤:鏈接錯誤:缺少vtable

enter image description here


Instrument class看起來是這樣的:

class Instrument { 

private: 

public: 

    virtual float getSample(Note &note); 
    Instrument(){} 

}; 

而且它通過實現我的Synth class

class Synth : public Instrument{ 

private: 
    Volume volume; 
public: 
    Synth(){} 
    void setVolume(float aVolume); 
    virtual float getSample(Note &note); 
}; 

我使用樂器作爲我的中的成員210:

class Track { 
public: 
    bool muted; 
    Instrument instrument; 
Track(){ 
    this->muted = false; 
} 
}; 

任何想法是什麼造成的問題?我還有一個問題:如果有Track對象,將instrument成員初始化爲Synth的最佳方法是什麼?這會工作嗎?

Track track; 
track.instrument = Synth(); 
+1

你忘記提及任何關於課程的功能。 – SingerOfTheFall 2012-08-15 11:45:27

回答

5

如注的錯誤說,你需要提供虛函數的定義,缺少我猜:Instrument::getSample(Note &note);

,但我猜你需要純虛函數,使其:

class Instrument { 
//... 
public: 
    virtual float getSample(Note &note) =0; 
    Instrument(){} 
}; 

如果不是這種情況,發佈更多的代碼並檢查你的代碼在不同的編譯器上,可能你的編譯器是buggy

+0

這工作。謝謝 – networkprofile 2012-08-15 13:09:33