Re: C++ design question
From: Simon Elliott (Simon)
Date: 09/29/04
- Next message: Mark Nicholls: "Re: SubTyping versus SubClassing"
- Previous message: Universe: "Re: SubTyping versus SubClassing"
- In reply to: Universe: "Re: C++ design question"
- Next in thread: Universe: "Re: C++ design question"
- Reply: Universe: "Re: C++ design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Sep 2004 08:47:19 GMT
On 28/09/2004, Universe wrote:
> > > barDerived(int i1, int i2):i2_(i2),barBase(i1){}
>
> > ^ Please explain the above line. ^
> >
> > Elliott
>
> The reason I ask is because as I understand doing:
>
> > > barDerived(int i1, int i2):i2_(i2),barBase(i1){}
>
> does not initialize the specific base class instance created as a part
> of creating an instance of this derived class if that was the intent.
Are you sure? My reading of the C++ standard (12.6.2) and tracing the
flow of execution in the debugger seem to indicate otherwise.
> 1) The derived classes ctor expressions do not initialize their base
> class instance part if that is the intent. They initialize some base
> class instance, but by the time one gets to initializing a base class
> instance the base class instance that is part of the derived class is
> *already* constructed and incorporated into the larger derived class
> instance.
As above, are you sure about this?
> 2) It is definitely not recommended in C++ to attempt to initialize
> the base class instance part of a derived class instance from a
> derived class instance in the same statement that creates the derived
> class instance.
>
> Off the top I would create a structure 'struct' external to both the
> base and derived classes that holds the derived classes members that I
> want their base classes to interact with.
> See "Fragile Base Class' in Struvstrup's FAQ at his web site for more
> particulars on the external structure solution.
I can't find a reference to this anywhere on
http://www.research.att.com/~bs/. Do you have any other pointers to
this issue?
-- Simon Elliott http://www.ctsn.co.uk
- Next message: Mark Nicholls: "Re: SubTyping versus SubClassing"
- Previous message: Universe: "Re: SubTyping versus SubClassing"
- In reply to: Universe: "Re: C++ design question"
- Next in thread: Universe: "Re: C++ design question"
- Reply: Universe: "Re: C++ design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|