| | |
downcasting and dynamic_cast
![]() |
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
I've gone through several books they explain Upcasting as
Base class pointer pointing to Drived class Object
this definition is correct.
Downcasting:
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
I know that downcasting is performed between polymorphic types
. I m bit confused with its definition and implementation... please give me the solid concept
.
Base class pointer pointing to Drived class Object
this definition is correct.
Downcasting:
•
•
•
•
Drived class pointer pointing to base class object..
if the above definition is correct... whats wrong with the below code
C Syntax (Toggle Plain Text)
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
. Hmm. Clues here: http://www.gotw.ca/gotw/017.htm ?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Why use dynamic cast (C++)
- Casting in C++ (C++)
- C++ Identifiers and Keywords (C++)
- Catching exceptions in C++ (C++)
Other Threads in the C Forum
- Previous Thread: Finish my DATABASE using C
- Next Thread: swapping
Views: 1818 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays binary binarysearch c++ centimeter char character code coke command conversion convert curl database decimal directory dude dynamic error exec factorial fgets file fork function functions getline givemetehcodez grade graphics gtkwinlinux haiku homework i/o inches input insert int integer lazy line linked linkedlist linux list lists loop malloc match matrix memory multi mysql no-effort numbers output path permutations pointer pointers problem process program programming read readfile recursion recursive recv recvblocked reverse scanf scheduling select shape socketprograming sockets spoonfeeding stdin string strings strtok structures student subscript system testautomation turbo-c txt unix user variable visualstudio voidmain() whythiscodecausesegmentationfault win32 windows _getdelim






