我有一个Track
包含Note
对象的 multimap 成员的类。Note
该类的方法之一是:
float Note::getValue(){
float sample = generator->getSample(this); // not working
return sample;
}
Note
也有一个Generator
类型的成员,我需要调用getSample
该类的方法,该方法需要一个Note
作为参数。我需要传递当前Note
对象并尝试使用关键字这样做,this
但这不起作用并给我错误Non-const lvalue reference to type 'Note' cannot bind to a temporary of type 'Note *'
。
这是方法定义的getSample
样子:
virtual float getSample(Note ¬e);
正如你所看到的,我使用了一个引用,因为这个方法被非常频繁地调用并且我不能复制对象。所以我的问题是:有什么想法可以完成这项工作吗?或者也许将我的模型更改为可以工作的东西?
编辑
我忘了提到我也尝试过使用generator->getSample(*this);
,但这也不起作用。我收到此错误消息:
Undefined symbols for architecture i386:
"typeinfo for Generator", referenced from:
typeinfo for Synth in Synth.o
"vtable for Generator", referenced from:
Generator::Generator(Generator const&) in InstrumentGridViewController.o
Generator::Generator() in Synth.o
Generator::Generator(Generator const&) in InstrumentGridViewController.o
Generator::Generator() in Synth.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的Generator
类的样子(getSample 方法在子类中实现):
class Generator{
public:
virtual float getSample(Note ¬e);
};