dynamic_cast with RefereceCountedObjectPtr

3 posts / 0 new
Last post
Shlomi
Offline
Last seen: 5 months 1 week ago
Joined: 28 Dec 2010 - 13:06
dynamic_cast with RefereceCountedObjectPtr

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!

Edited by: Shlomi on 14 Jun 2012 - 13:27
haydxn
Offline
Last seen: 9 hours 4 min ago
Joined: 10 Apr 2005 - 14:46
Re: dynamic_cast with RefereceCountedObjectPtr

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

Shlomi
Offline
Last seen: 5 months 1 week ago
Joined: 28 Dec 2010 - 13:06
Re: dynamic_cast with RefereceCountedObjectPtr

Awesome!

dynamic_cast< MyReferenceCountedClass* > (myRefereceCountedObjectPtr.getObject())

did the job.

Thanks haydxn!