基类和派生类指针的相互赋值和转换 intmain() { CDerived objDerived(3); CBase objBase(5); CBase* pBase = &objDerived;//使得基类指针指向派生类对象//pBase->Func();//错, CBase类没有Func()成员函数//pBase->v = 5;//错 CBase类没有v成员变量pBase->Print();//可以访问自己有的部分 cout<...
基类指针和派生类指针相互赋值的原理是啥?#include <iostream> using namespace std; class A { public: virtual voidsprint() { cout<<"A"<<endl; } A() { } void sayhiA() { cout<<"say hi from A"<<endl; } }; class B:public A { ...
基类指针和派生类指针相互赋值的原理是啥?#include <iostream>using namespace std;class A{public:virtual voidsprint(){cout<<"A"<<endl;}A(){}void sayhiA(){cout<<"say hi from A"<<endl;}};class B:public A{public:B(){}void sprint(){cout<<"B"<<endl;}void sayhiB(){cout<<"say hi...