I have an interface called Generator that looks like this:
class Generator{
public:
virtual float getSample(Note ¬e)=0;
};
And my Synth class is implementing it, like this:
class Synth : public Generator{
public:
virtual float getSample(Note ¬e);
};
float Synth::getSample(Note ¬e){
return 0.5;
}
I’m trying to call the getSample method from my Note class (which has a generator member)
class Note : public Playable{
public:
Generator *generator;
virtual float getValue();
};
float Note::getValue(){
float sample = generator->getSample(*this); // gets stuck here
return sample;
}
When I try to run, it gets stuck on the marked line in the code above. The problem is that I’m not getting a very clear error message. This is what I can see once it stops:


It seems like you never initialized the member
Note::generator, so calling a function on it is undefined behavior.Try, as a test:
If it works, go back and review your logic. Use a
std::unique_ptr<Generator>instead of a raw pointer. Create a constructor forNode. Initialize the pointer there.