????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??????