我有一个接口称为发电机,看起来像这样:继承执行不工作
class Generator{
public:
virtual float getSample(Note ¬e)=0;
};
而且我Synth
类实现它,像这样:
class Synth : public Generator{
public:
virtual float getSample(Note ¬e);
};
float Synth::getSample(Note ¬e){
return 0.5;
}
我想打电话给getSample方法从我的Note类(它有一个生成器成员)
class Note : public Playable{
public:
Generator *generator;
virtual float getValue();
};
float Note::getValue(){
float sample = generator->getSample(*this); // gets stuck here
return sample;
}
当我尝试运行时,它会卡在上面代码的标记行中。问题是我没有得到一个非常明确的错误信息。这是我可以看到,一旦它停止:
您确定生成器成员已初始化('EXC_DAB_ACCES'似乎表明不然)?你也应该使用智能指针而不是原始指针。 – stijn