我电脑运行结果是4,4,4,8,4,按这个看,基类的虚函数指针似乎不会在派生类中复制?
#include <string>
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class A {
public:
virtual int fun() {return 1;}
};
class E : public A {
public:
virtual int fun() {return 5;}
};
class B : virtual public A {
public:
virtual int fun() {return 2;}
};
class C : virtual public A {
public:
virtual int fun() {return 3;}
};
class D : public B, public C {
public:
virtual int fun() {return 4;}
};
int main()
{
cout << sizeof(A) << endl; // 4
cout << sizeof(B) << endl; // 4
cout << sizeof(C) << endl; // 4
cout << sizeof(D) << endl; // 8
cout << sizeof(E) << endl; // 4
return 0;
}