inheritance and memory layout

Discussion in 'C++' started by Anargyros L. Papadopoulos, Mar 8, 2005.

  1. 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?
     
    Anargyros L. Papadopoulos, Mar 8, 2005
    #1
    1. Advertising

  2. EventHelix.com, Mar 8, 2005
    #2
    1. Advertising

  3. Anargyros L. Papadopoulos

    Guest

    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
     
    , Mar 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    3
    Views:
    3,168
    Rick Spiewak
    Aug 26, 2003
  2. Replies:
    1
    Views:
    598
    John Timney \(MVP\)
    Jun 19, 2006
  3. Edsko de Vries
    Replies:
    0
    Views:
    945
    Edsko de Vries
    Jan 9, 2006
  4. Replies:
    1
    Views:
    631
    Thomas Tutone
    Oct 8, 2006
  5. Ge Chunyuan
    Replies:
    0
    Views:
    967
    Ge Chunyuan
    Jul 23, 2007
Loading...

Share This Page