0

I've gone through several books they explain Upcasting as
Base class pointer pointing to Drived class Object

this definition is correct.
Downcasting:

Drived class pointer pointing to base class object..

i got a bit confused.....not having crystal clear image in my mind.....
if the above definition is correct... whats wrong with the below code

class Shape {
public:
   virtual ~Shape() {}
};
class Circle: public Shape {
public: 
   ~Circle() {} 
};
 
int main() 
{
      //why this can't work ...........according to definition....
    //  Circle* c = dynamic_cast<Shape*>(new Shape);
 
     //why this
     Shape* s = new Shape;
     Circle* c = dynamic_cast<Circle*>(s);
     return 0;
}

I know that downcasting is performed between polymorphic types :) . I m bit confused with its definition and implementation... please give me the solid concept ;) .

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Dave Sinkula
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.