mihai11@mailcity.com (Razvan) wrote in
news:15f19d61.0406211206.66da6ecf@posting.google.c om:
[color=blue]
> Hi!
>
>
>
> What is wrong with the following code ?
>
>
> // Test1.cpp : Defines the entry point for the console application.
> //
>
> #include "stdafx.h"
>
>
> class CTest1
> {
> public:
> CTest1(){}
> virtual ~CTest1() = 0;
> };
>
> class CTest2: public CTest1
> {
> public:
> CTest2(){}
> virtual ~CTest2(){}
> };
>
>
>
> int main(int argc, char* argv[])
> {
> printf("Hello World!\n");
>
> CTest2 test;
>
>
> return 0;
> }
>
> Because the desctructor for the class CTest1 is pure virtual I
> cannot
> instantiate variables of type CTest2 ?!! Since the destructor is
> not inherited the only option is to provide a body for the pure
> virtual destrcutor. (I forgot to mention that I get a linker error on
> VC++6.0 and VC++7.0)
> Is this normal behaviour ? I mean why I cannot instantiate CTest2
> ?
> Because the destructor is not inherited the fact that the base
> destructor is pure virtual should be irrelevant.[/color]
This is normal. Recall that when CTest2 goes out of scope, the
destructor for CTest2 must be executed, and so must the destructor for
the base class, CTest1! Note that destructors (and constructors for that
matter) aren't inherited, but they do get invoked through other
mechanisms.