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 ;) .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.