2012-08-15 146 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