#include <iostream>
using std::cout;
using std::endl;
class Base1 {
public:
Base1() :a_(100) {}
virtual void fun1() { cout << "Base1.fun1" << endl; }
virtual void fun2() { cout << "Base1.fun2" << endl; }
private:
int a_;
};
class Base2 {
public:
Base2() :b_(200) {}
virtual void fun3() { cout << "Base2.fun3" << endl; }
virtual void fun4() { cout << "Base2.fun4" << endl; }
private:
int b_;
};
class Derived : public Base1, public Base2 {
public:
Derived() :d_(300) {}
virtual void fun1() override { cout << "Derived.fun1" << endl; }
virtual void fun2() override { cout << "Derived.fun2" << endl; }
virtual void fun3() override { cout << "Derived.fun3" << endl; }
virtual void fun4() override { cout << "Derived.fun4" << endl; }
private:
int d_;
};
int main()
{
Derived derived;
cout << (int *)&derived << endl;
getchar();
return 0;
}
下图是VS2017的调试窗口显示的相关地址信息
derived地址空间分布图
转载:https://blog.csdn.net/dyingfair/article/details/104599692
查看评论