Derived 派生类

#include "stdafx.h"
#include "iostream"

using namespace std;


class Base1
{
public:
virtual void show() = 0;
};
class Base2
{
protected:
char* _p;
//char* s的地址是00f8dae0
Base2(const char *s)
{
//_p的地址是0077ae68
_p = new char[strlen(s) + 1];
strcpy(_p, s);
}
~Base2()
{
delete[] _p;
}
};

class Derived:public Base1,private Base2
{
public:
Derived(const char* s) :Base2(s){}
void show()
{
cout << _p << endl;
}
};
int _tmain()
{
//0x00f8dac8虚函数表-》指向0x00f814c4
//当Base1对象pb不是指针时 “Base1”: 不能实例化抽象类
Base1* pb =new Derived("I'm a derived class .");
//想知道虚函数表有两个地址分别占用多少字节
pb->show();
delete pb;
return 0;
}

posted @ 2016-04-10 10:02  huninglei  阅读(308)  评论(0编辑  收藏  举报