| | |
downcasting and dynamic_cast
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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: 1599 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
* api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function functions getlogicaldrivestrin givemetehcodez global graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked reversing scheduling segmentationfault send single socketprogramming spoonfeeding standard strchr string student suggestions system test testautomation testing unix urboc user whythiscodecausesegmentationfault win32api windowsapi






