inheritance and memory layout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anargyros L. Papadopoulos

    inheritance and memory layout

    given:
    class A {
    // ...
    };

    class B : public class A {
    // ...
    }

    void some_fun()
    {
    B b;
    A *pa = &b;
    B *pb = &b;

    if ((void *)pa == (void *)pb) {
    ;
    } else {
    // is it possible ??
    ;
    }
    }

    is it guarantee (from the standard), assuming single inheritance, that it is
    impossible to reach the else statement in the above code?


  • EventHelix.com

    #2
    Re: inheritance and memory layout

    With single inheritance, yes it is impossible to reach the else
    statement.

    The following article should help:



    Deepa
    --
    EventStudio 2.5 - http://www.EventHelix.com/EventStudio
    Generate Sequence diagrams from a simple declarative language

    Comment

    • rajkumar@hotmail.com

      #3
      Re: inheritance and memory layout

      The said link just presents one way of implementing virtual functions.
      I dont think standard says anything about how to implement virtual
      functions.

      The OP had asked in case of singled inheritance if else branch can be
      true.

      I think it can be if the user overloads & operator for B and does
      something crazy

      raj

      Comment

      Working...