基类指针赋值兼容规则
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;}
相关文章推荐
- 强制类型转换为基类指针与赋值兼容规则下转换为基类指针的比较
- 【总结】C++基类与派生类的赋值兼容规则
- 钻石继承、虚基类、赋值兼容规则
- [c++]基类对象作为函数參数(赋值兼容规则)
- [c++]基类对象作为函数参数(赋值兼容规则)
- 【总结】C++基类与派生类的赋值兼容规则
- 赋值兼容规则
- c++赋值兼容规则
- 浅谈C++ 基类指针和子类指针的相互赋值
- C++赋值兼容规则和类类型转换注意事项之一
- 基类指针和子类指针相互赋值
- 赋值兼容规则
- 基类和派生类的赋值规则
- C++编程入门系列之四十三(继承与派生:赋值兼容规则)
- C++指针之间的赋值与转换规则总结
- 继承中的支配规则和赋值兼容规则
- C++:基类与派生类对象之间的赋值兼容关系
- C++中的继承(3)作用域与重定义,赋值兼容规则
- C++赋值兼容规则和多态
- 【继承与多态】C++:继承中的赋值兼容规则,子类的成员函数,虚函数(重写),多态