Discussion: Copy constructors
Afficher un message
Vieux 18/10/2007, 16h37   #4
Joe Greer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Copy constructors

keith@bytebrothers.co.uk wrote in news:1192721104.884316.307060
@k35g2000prh.googlegroups.com:

> On 18 Oct, 16:06, Barry <dhb2...@gmail.com> wrote:
>> ke...@bytebrothers.co.uk wrote:
>> > Now this all compiles and works just fine, but when I turn on "-Wall -
>> > W" in gcc, it tells me that:

>>
>> > derived.cc:134: warning: base class 'class Base' should be explicitly
>> > initialized in the copy constructor

>>
>> > I'm afraid I'm being rather dense today, as I don't understand what
>> > it's complaining about. Can someone explain for me please?

>>
>> It complains that you should write your Derived ctor in this way:
>>
>> Derived:erived()
>> : Base()
>> , p_(new DerivedPrivate())
>> {}

>
> OK, this makes the warning go away - thanks. Now, what's happening?
> I thought that by the time we reached Derived's constructor (in this
> case, copy constructor), Base was guaranteed to have been fully
> constructed. This result implies I am wrong...
>


Don't read too much into the syntax. This basically just tells the
compiler which constructor to use for the base class and provides the
opportunity to provide parameters to the base class' constructor. By the
time your Derived member initialization occurs and your constructor body is
executed, the base class will have been initialized.

joe
  Réponse avec citation
 
Page generated in 0,05467 seconds with 9 queries