CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: casting

  1. #1
    Join Date
    Jun 1999
    Posts
    176

    casting

    In the past year or so, I've seen casting like:

    CObj* x = static_cast<CObj*> (y);




    Is there any advantages of using static_cast instead of the good old casting like:

    CObj* x = (CObj*)y





    -= hm... =-
    Grace


  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: casting

    Short answer:
    A static_cast is stricter about the conversions it allows.

    For example: unlike the old C/C++ style cast (your example 2), it won't convert function pointers unless it can convert all the arguments and return types.
    However, that static_cast does not perform a run-time check.


    I don't do it for ratings, but appreciation is always in style.
    Good luck in your journey in a C++ land.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured