Re: from a tutorial

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David (dfoster_at_woofix.local.dom)
Date: 12/09/04


Date: Thu, 09 Dec 2004 03:41:25 -0800

On 2004-12-09, Herfried K. Wagner [MVP] <hirf-spam-me-here@gmx.at> wrote:
> "rodchar" <rodchar@discussions.microsoft.com> schrieb:
>> Does this mean that if this class gets instantiated there will be 2
>> objects
>> because of the MyBase.New line? what would be the reasons for using the
>> line
>> mybase.new?
>
> It's one object, but each instance of the derived class is an instance of
> the base class too (inheritance /extends/ the base class, it adds something
> to it). That's why the base class' constructor has to be called. There are
> some situations where it's not necessary to explicitly call it -- in these
> cases, the compiler will add the call to the base class' 'New' method.

And in fact this is one of those times. If the call to MyBase.New were
deleted, the compiler would implicitly put it right back in anyway.



Relevant Pages

  • Re: Two questions
    ... When defining a class A, ... >Will the compiler provide a constructor for it? ... When defining a copy constructor and assignment operator for a base ... >class, and the base class is inherited by a child class, will the child ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Two questions
    ... When defining a class A, ... >>Will the compiler provide a constructor for it? ... When defining a copy constructor and assignment operator for a base ... >>class, and the base class is inherited by a child class, will the child ...
    (alt.comp.lang.learn.c-cpp)
  • Re: copy ctor question
    ... > for each member and base class. ... The compiler generated copy constructor isn't ... > do proper copy semantics themselves. ... Secondly you can't put a breakpoint on a compiler generated ...
    (comp.lang.cpp)
  • Re: Call constructor/destructor of base class
    ... > You don't 'call' a constructor explicitely. ... > automatically by compiler as a side effect of object creation. ... It's a bit simpler to say that object creation is an unavoidable side ... Namely constructors for members, including base class constructors. ...
    (comp.lang.cpp)
  • Re: Free FAT16 Filesystem
    ... >standard of care is less than yours, ... Of course, regardless ... For several reasons: ... >both your compiler AND under Keil's, ...
    (comp.arch.embedded)