dynamic_cast with RefereceCountedObjectPtr

Discussion and support for general JUCE issues

dynamic_cast with RefereceCountedObjectPtr

Postby Shlomi » Thu Jun 14, 2012 1:18 pm

Hello everybody!

I have an inheritance chain of ReferenceCountedObjects and I want to be able to detect the exact type of a specific ReferenceCountedObjectPtr instance.
(each ReferenceCountedObject object has its own ReferenceCountedObjectPtr object)

The compiler rejected all of my dynamic_cast attempts, how can I find the exact type?

Thanks!
Last edited by Shlomi on Thu Jun 14, 2012 1:27 pm, edited 1 time in total.
User avatar
Shlomi
JUCE UberWeenie
 
Posts: 395
Joined: Tue Dec 28, 2010 2:06 pm

Re: dynamic_cast with RefereceCountedObjectPtr

Postby haydxn » Thu Jun 14, 2012 1:25 pm

ReferenceCountedObjectPtr is not a base, it is a template, so you cannot dynamic_cast such a pointer object.

You could, however, use dynamic_cast on the actual pointer it contains. This would be to the Object, rather than the Ptr class; this is obviously not quite the same as what you're asking for, but I can't think of a single reason why casting to the correct Ptr class would be useful, since the object is what matters.
xh
User avatar
haydxn
JUCE UberWeenie
 
Posts: 1184
Joined: Sun Apr 10, 2005 2:46 pm
Location: Manchester, UK

Re: dynamic_cast with RefereceCountedObjectPtr

Postby Shlomi » Thu Jun 14, 2012 1:43 pm

Awesome!

Code: Select all
dynamic_cast< MyReferenceCountedClass* > (myRefereceCountedObjectPtr.getObject())


did the job.

Thanks haydxn!
User avatar
Shlomi
JUCE UberWeenie
 
Posts: 395
Joined: Tue Dec 28, 2010 2:06 pm


Return to General JUCE discussion

Who is online

Users browsing this forum: No registered users and 1 guest