casting operators

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankushganatra
    New Member
    • Dec 2007
    • 3

    casting operators

    Hi can u please explain me the difference between <static_cast> and <dynamic_cast>. ...?
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by ankushganatra
    Hi can u please explain me the difference between <static_cast> and <dynamic_cast>. ...?
    I think searching in the net will give you a good idea about this.
    I suggest this link to start with.
    After reading the tutorial you can come back here and post the questions

    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      The essential difference is that static_cast is a compile time cast whereas dynamic_cast is a runtime cast. That is, the types being used are checked at compile time for static_cast and runtime for dynamic_cast.

      Also, dynamic_cast needs RTTI turned on to make that runtime type identification. That feature is a big resource hit.

      Which leads me to: Why are you casting anyway??

      These C++ cast forms are for emergencies and are not intended to be part of a design.

      Comment

      Working...