请问一道memory layout的题目(急)
17860
向大家请教一道memory layout相关的题目:代码如下:
class Base1
{
public:
virtual int virt1() { return 100; }
int data1;
};
class Derived : public Base1
{
public:
virtual int virt1() { return 150; }
int derivedData;
};
Base1 的 memory layout是:
Virtual Pointer to virtual method table of Base1;
data1;
Derived 的 memory layout是:
Virtual Pointer to virrtual method table of D(for Base1);
data1;
derivedData;
问题是在Derived的memory layout中是否可以把data1和derivedData的位置进行交换?? 我觉得是不可以的,因为compiler compile的顺序是先base class的variable,然后才是derived class的variable, 如果这样就会把base class的variable和derived class 的variable颠倒过来,最后结果就不对了。我不知道这么想对不对,请各位指教
十分谢谢!!!
class Base1
{
public:
virtual int virt1() { return 100; }
int data1;
};
class Derived : public Base1
{
public:
virtual int virt1() { return 150; }
int derivedData;
};
Base1 的 memory layout是:
Virtual Pointer to virtual method table of Base1;
data1;
Derived 的 memory layout是:
Virtual Pointer to virrtual method table of D(for Base1);
data1;
derivedData;
问题是在Derived的memory layout中是否可以把data1和derivedData的位置进行交换?? 我觉得是不可以的,因为compiler compile的顺序是先base class的variable,然后才是derived class的variable, 如果这样就会把base class的variable和derived class 的variable颠倒过来,最后结果就不对了。我不知道这么想对不对,请各位指教
十分谢谢!!!
0条回复