基类指针赋值兼容规则

/*
   赋值兼容规则
   作者:qpz
 */
#include <iostream>
#include <vector>
using namespace std;
class Base{
private:
int x;
int y;
public:
Base(int x,int y)
{
this->x=x;
this->y=y;
}
};
class Derived:public Base{
private:
int z;
public:
Derived(int z):Base(z-1,z+1)
{
this->z=z;
}
};
int main(void)
{
//Derived *p=new Base(2,1);//因为派生类指针映射范围大
 Base *p=new Derived(1);
 delete p;
return 0;
}

posted @ 2014-12-15 20:56  机智的程序员小熊  阅读(106)  评论(0编辑  收藏  举报