Re: replicated base classes

From: ma740988 (ma740988_at_pegasus.cc.ucf.edu)
Date: 02/08/04


Date: 7 Feb 2004 21:08:20 -0800

Richard Heathfield <dontmail@address.co.uk.invalid> wrote in message news:<c0290e$ci3$1@hercules.btinternet.com>...

> > class A{};

>
> Let's find out.
>
> $ cat foo.cpp
> #include <iostream>
> using namespace std; /* yeah, I know, I know, but it's just a quickie */
>
> class A
> {
> public:
> A() { cout << "class A constructor" << endl; }
> ~A() { cout << "class A destructor" << endl; }
> };
>
The fact that you did not use the free store allows for a non virtual
destructor?
I've done so much reading but i seem to recall the need for a virtual
destructor in a base class if there's derived classes.

> class B : public A
> {
> public:
> B() { cout << "class B constructor" << endl; }
> ~B() { cout << "class B destructor" << endl; }
> };
>
I also see to recall that as long as the base has virtual destructor
then the derived classes does not warrant virtuals. Yes??

> class C : public A
> {
> public:
> C() { cout << "class C constructor" << endl; }
> ~C() { cout << "class C destructor" << endl; }
> };
>
> class BC : public B, public C
> {
> public:
> BC() { cout << "class BC constructor" << endl; }
> ~BC() { cout << "class BC destructor" << endl; }
> };
>
> int main()
> {
> BC test;
> return 0;
> }
>
> $ make
> g++ -W -Wall -ansi -pedantic -O2 -g -pg -o foo foo.o
>
> $> ./foo
> class A constructor
> class B constructor
> class A constructor
> class C constructor
> class BC constructor
> class BC destructor
> class C destructor
> class A destructor
> class B destructor
> class A destructor
>
> Does that answer your question?



Relevant Pages

  • Re: cant establish connection to Domino Server
    ... In Constructor of CABProvider ... WINAPI OpenServiceProfileSection ... In Destructor of CNotesExchExt ... AllocateAndCopyString ...
    (microsoft.public.outlook.interop)
  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.lang.c)
  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.programming)
  • Re: Best way to deal with long loops?
    ... var ts:TCallbackTimer; ... destructor TCallbackTimer.destroy; ... constructor TRunningAverage.Create; ... // and currenttick will be wrapped, ...
    (alt.comp.lang.borland-delphi)
  • Re: replicated base classes
    ... > destructor in a base class if there's derived classes. ... If you have a variable of type 'pointer to base class' that actually ... The derived class does warrant virtuals, ...
    (alt.comp.lang.learn.c-cpp)

Loading