您的位置:首页 > 其它

基类指针赋值兼容规则

2014-12-15 20:56 288 查看
/* 赋值兼容规则 作者: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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: