派生类对象

时间:2015-09-09 02:05:40

标签: c++ pointers object inheritance

如果我有一个派生类对象,基类对象总是位于该对象的开头吗?

例如,在下面的代码中,A&C的对象保证在所有实现中都放在B对象的开头。

我已经看到基本成员的这种放置总是但不知道它是否是一个定义的标准。如果是这种情况,它如何与多重继承一起使用?

class A
{
    public:
        int a;
        int b;
};

class B : public A
{
    public:
        int c;
        int d;
};

int main ()
{
    B obj;

    // Is B.a always guaranteed to be at the top i.e. 
    // Object arranged as
    /*
    {
       a;
       b;
       c;
       d;
    }
    */
}

0 个答案:

没有答案