المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : V-tables



C++ Programming
04-17-2009, 06:53 PM
Sorry about the vague subject title, but I can't really think of a better way to describe it. Say I have this class:
class Foo
{
public:
Foo();
~Foo();
virtual void DoSomething(void *p)
{
if(Next)
Next->DoSomething(p);
}
Foo *Next;
};
I derive from it:
class Bar : public Foo
{
public:
Bar();
~Bar()
void DoSomething(void *p)
{
if(p)
free(p);
}
};
Say I call Bar->DoSomething((void *)0x1234). It will (hopefully) free the pointer. Is there any way to ensure that Bar does what it wants, then drops down to Foo's implementation afterwards?