This forum has been archived. Please start a new discussion on GitHub.

smart pointer down cast


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?