Re: COMPILE!
From: JKop (NULL_at_NULL.NULL)
Date: 08/05/04
- Next message: JKop: "Re: typedef doubt"
- Previous message: NG: "typedef doubt"
- In reply to: tom_usenet: "Re: COMPILE!"
- Next in thread: JKop: "Re: COMPILE!"
- Reply: JKop: "Re: COMPILE!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 05 Aug 2004 18:07:34 GMT
>> ~AutoDestructive()
>> {
>> this->CleanUp();
>
> There's your problem - calling a virtual function from a destructor
> doesn't do what you think it does. Calling a pure virtual function
> from a destructor causes undefined behaviour (and fortunately VC seems
> to indicate this with a linker error, which is as nice as undefined
> behaviour gets).
>
> Basically, destruction goes for typical implementations:
>
> derived class destructor called
> derived members destructed in reverse order of declaration
> *vtable pointer updated to point to base class vtable*
> base class destructor called
> base class members destructed in reverse order of declaration
>
> The emphasised line is what causes the problem for you - calling a
> virtual function from a constructor or destructor calls the function
> in the base object currently being constructed or destructed, not the
> one in the most derived class.
>
> Tom
Okay, is there anything wrong with the following though? It compiles for me:
class Base
{
public:
virtual void Monkey() = 0;
void HelperMonkey()
{
this->Monkey();
}
~Base()
{
HelperMonkey();
}
};
class Derived : public Base
{
public:
virtual void Monkey()
{
}
};
int main()
{
Derived checker;
}
-JKop
- Next message: JKop: "Re: typedef doubt"
- Previous message: NG: "typedef doubt"
- In reply to: tom_usenet: "Re: COMPILE!"
- Next in thread: JKop: "Re: COMPILE!"
- Reply: JKop: "Re: COMPILE!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|