C++?е????????????????????
???????????? ???????[ 2012/10/17 10:16:06 ] ????????
????1.3 ???“???????”
???????????????????麯???????????????????????????ú??????????????????麯???????????α???????????????Lippman????????C++???????[1]?е???????????????????????“?????”?????????????
???????????“???”??????????ν??“VTABLE”???????????????????????б??????virtual?????????????????麯????????VTABLE??VTABLE?????????????????????飬????麯????????????????slot?????????????VTABLE?????????ж??????????????????????VTABLE?????????????VTABLE??????VTABLE???????????????????????麯????????????????????λ??????????????????????????????????????????沼???????????vptr??Σ????????????VTABLE???????Щ??Σ????????????????麯????????????????????д?????1.1?е??????
void bar(A * a)
{
a->foo();
}
????д???
void bar(A * a)
{
(a->vptr[1])();
}
??????????????????foo()?????????????VTABLE?????????????vptr????????VTABLE????????????????????????????????????????foo()??????
????????????????????????????????????????
????1.4 overload??override
?????麯???????????????б???д???????д?????“override”???????????“overload”??“override”??????????????????????C++????????????????????????????????????????????????????????£?
????override???????????д??????麯?????????????B??????д??A???е?foo()????????д?????????????μ?????????????C++?????????????????????????????“??”????????????????????????????feature??????????????????????????????????????????????“????”?????????Щ??
????overload??????????????“????”???????д????????к?????????????????????????????????????????????????????????????????????????????????
????2???麯??????
?????麯????????“virtual”??????
????2.1 ???virtual?????
????????????????Σ?
class A
{
public:
virtual void foo();
};
class B: public A
{
public:
void foo(); // ???virtual?????!
};
class C: public B // ??B??У??????A??У?
{
public:
void foo(); // ????virtual??????
};
????????????£?B::foo()???麯????C::foo()???????麯??????????????????????????麯??????????????????麯??????????????virtual??????
??????
???·???
??????????????????
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