?????????????麯???????????
???????????? ???????[ 2013/1/30 9:55:39 ] ????????
?????????з??????????C++???????????????????????????????????????д??????????С?????????????????????????????
#include <iostream>
using namespace std;
class Base
{
public:
virtual void funtion(int arg = 1){cout<<arg<<endl;}
};
class Derive : public Base
{
public:
virtual void funtion(){cout<<"Derive"<<endl;}
virtual void funtion(int arg){cout<<"Derive"<<arg<<endl;}
};
int main(int argc?? char *argv[])
{
Base* obj = new Derive();
obj->funtion();
system("pause");
return 0;
}
??????????????????????????????к??????????????????????????????????“??????????”???????????????????????3??????????????????????????????????????????????arg?????????????е??1?????н???“Derive 1”??
??????????????????????????????????????????????????????????????????
????????????????????????????????????
????????????????????????????????
???????磺
Base *pgo= //pgo?????????Base *
new Derive; //?????????Derive *
Asterioid *pa = new Asterioid; //pa?????????? Asterioid *
//?????????? Asterioid *
pgo = pa; //pgo????????????Base *
//???????????? Asterioid *
Base &rgo = *pa; //rgo??????????Base
//????????? Asterioid
?????麯??????????????????????????????????Ч??????????????????????????????????????????????????????????麯??????????????????????????????????C++????????????????????????????????????????????????????C++??????????????????????????????Ч????е?????????????????????飬???????????
????????????????????[Effective C++??3??]????????????36?????????????????麯??????????塣???濴?????е???????
??????????????μ??ν???B?????????D????B????м????B???ж???????????г??????mf??????????mf?????????????????????????????mf??????????????????????????
class B {
public:
void mf();
};
class D: public B { };
????????B??D??mf???κ???????????????????D?????x??
D x; // x ??D????????
B *pB = &x; // ???x?????
pB->mf(); // ?????????mf????
D *pD = &x; // ???x?????
pD->mf(); // ?????????mf????
???????????????????pD->mf()??pB->mf()??????в????????????????е??????????????????ζ????????x???????????mf???????????????????????????????????mf()??????????????μ???????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11