ReferenceCountedObject and dynamic_cast to var

I'm having some trouble working this out - how to cast a ReferenceCountedObject to a var so I can set it as a property of a ValueTree. 


I have an Array of RationalNum objects called ratios. I want to pass one in (referenced by index i) as a property of a ValueTree. 

I have defined RationalNum as:

class RationalNum : public ReferenceCountedObject

    RationalNum(double value);

    RationalNum(int numerator, int denominator);

    typedef ReferenceCountedObjectPtr<RationalNum> Ptr;


 I'm obviously not understanding something fundamental about this, if someone can point me to a working example would be much appreciated! 

Current code (which brings up a compiler error):

RationalNum::Ptr ratioPtr (ratios.getUnchecked(i));

myNode.setProperty (myNodeType, dynamic_cast <RationalNum*> (ratioPtr), nullptr);

Since I am introducing ValueTrees into my project I am considering moving the ratio values out of the RationalNum class altogether and storing them as a ValueTree instead.


I believe a "get" or "getObject" should do what you need.  So, ratioPtr.get() or ratioPtr.getObject().  Both methods do the same thing.

Thanks, I've added that in - but its the preceding line thats giving me the compiler issue:

No viable conversion from 'RationalNum' to 'RationalNum::Ptr' (aka 'ReferenceCountedObjectPtr<RationalNum>') 

Your samples don't show the declaration of the variable 'ratios'; since the error indicates that getUnchecked is not returning a pointer to your type, I assume ratios is an Array (when it should be ReferenceCountedArray).

Thank you,  yes that was the problem! Wondered what ReferenceCountedArray was for... cheers :)