Is this a safe and sane approach for using values?

ObjectA has some Value v and a method:

Value & getValueObject() { return v; }

ObjectB wants to know if the value changes. 

So in Object B I do (roughly): 

class ObjectB : public ValueListener {

ObjectB() {




 Value myInstance;

 ObjectA & objA;


And then I don't have to worry about whether I've removed the listener properly, because myInstance is removed as soon as Object B is destroyed.


Yep, that's the pattern I tend to use too!

Thank you for this, helped me in my current project (learning JUCE and C++ along the way...)


However - I'm encountering a build error: "allocating an object of abstract class type" for MainContentComponent. This seems to be to do with defining the necessary virtual functions. I've defined and declared 

void MainContentComponent::valueChanged(juce::Value *value)

Is there something else I may have missed? 


It's a reference, not a pointer.

Thanks, sorted 


void MainContentComponent::valueChanged(juce::Value *value) override

rather than 

void MainContentComponent::valueChanged(juce::Value *value);

in your interface when you intend to override a function, if you are doing C++11 anyway.  That way you'll get an error immediately if you've cocked it up.  There is a small problem in Xcode when using JUCE and override. It sometimes breaks the formatting when you write your function body in the header and you've got the override in there too.  I've reported it to Apple, but suspect it's pretty subtle, as it doesn't seem to  happen when the JUCE headers aren't included. 

Also, in the Xcode error messages on the left there's usually a little arrow, click that and it'll show you which function you haven't implemented.  I didn't notice that for ages ... I must have wasted a week of my life doing it manually :)