Archived
This forum has been archived. Please start a new discussion on GitHub.
smart pointer down cast
Hi,
Smart pointers in C++ are really convenient. However, I am a little confused with down casting a smart point to child class pointers.
Let's suppose we have the following SLICE class definitions:
The SLICE2CPP compiler will generate FruitPtr and ApplePtr.
Now in the application, suppose I have a FruitPtr p1 which actually points to an Apple instance, can I get a ApplePtr p2 from the p1 pointer like
even if this is the correct way, is there any other ways?
Regards,
Smart pointers in C++ are really convenient. However, I am a little confused with down casting a smart point to child class pointers.
Let's suppose we have the following SLICE class definitions:
class Fruit {} class Apple extends Fruit {}
The SLICE2CPP compiler will generate FruitPtr and ApplePtr.
Now in the application, suppose I have a FruitPtr p1 which actually points to an Apple instance, can I get a ApplePtr p2 from the p1 pointer like
ApplePtr p2 = (ApplePtr)p1;?
even if this is the correct way, is there any other ways?
Regards,
0
Comments
-
Hi Peter,
the correct way for do that isApplePtr p2 = ApplePtr::dynamicCast(p1);
Jose0 -
Thanks
Thank u very much for the pointer0 -
Hi Peter
Also this is documented here http://www.zeroc.com/doc/Ice-3.3.0/manual/IceUtil.48.7.html
Jose0