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

Threaded View

  1. #16
    Join Date
    Aug 2002
    Posts
    78
    Which, of course, brings us full circle to my subordinate question: The pointer returned IS actually altered.


    In the case of multiple inheritence, where B is an A and a C at the same time, the pointer must get changed. Why? If run typing is off (if that has anything to do with working around this issue) casting B* to a C*, then passing into a function that accepts a C* will have to receive a changed numerical value for the pointer variable. Inside that function, the compiler can't know that some of its C*'s are really pointers to a B*, and then do extra offsets from a "normal, pure" C*.

    In other words, passing in B* to a function that accepts an A* and another that accepts a C*, well, both functions HAVE to accept different numerical pointers.

    This is not the case with single inheritence (regardless of number of ancestors). The pointer is always to the top, "parent-est" object, and pointers to descendents are always handled as offsets from that ultimate parent's numerical address pointer.

    And if anyone digs out some document that says you can't make that assumption, then we must assume the pointers might be changed, and thus even for single inheritence, the pointer might get changed, and thus reinterpret_cast is always the wrong thing to use on object pointers, QED.
    Last edited by Gorgor; May 13th, 2004 at 09:56 AM.

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