Re: C++ design question

From: Bob Hairgrove (invalid_at_bigfoot.com)
Date: 09/30/04


Date: Thu, 30 Sep 2004 10:12:03 +0200

On Wed, 29 Sep 2004 20:05:26 GMT, "H. S. Lahman"
<h.lahman@verizon.net> wrote:

[snip]
>The OP's safety issue lay in initializing the reference object itself,
>not the instantiation of the embedded reference. The solution is to use
>the default constructor (which doesn't even have to be in the
>initializer list) to do that instantiation while doing the actual
>initialization of the reference object in the body via setters as I
>suggested.

Unfortunately, a reference member MUST be initialized in the
initialization list of the constructor of the class of which it is a
member. This is a C++ requirement. Your solution, while it may have
logical merits, is not possible in C++.

If you try to compile the example you gave, you'll see that no
compiler accepts the syntax (aside from the fact that "this" is a
pointer and needs -> instead of the dot).

--
Bob Hairgrove
NoSpamPlease@Home.com


Relevant Pages

  • Re: C++ design question
    ... references must be in the initializer list but the constructor argument ... instantiation and initialization, which is mostly hidden by the OOPL ... The OP's safety issue lay in initializing the reference object itself, ...
    (comp.object)
  • Re: Beginner level VB.NET question
    ... were a C# programmer. ... object to nothing somewhere in the code, but not realizing it is the same ... NullReferenceException;(Am I checking whether my reference Object is ... ' Initialization and other good stuff ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Beginner level VB.NET question
    ... were a C# programmer. ... object to nothing somewhere in the code, but not realizing it is the same ... NullReferenceException;(Am I checking whether my reference Object is ... ' Initialization and other good stuff ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Cant get static SolidBrush to initialize... what am I missing
    ... The order of instantiation problem is amazing given the way I have it setup. ... At the file scope I attempted to instantiate the Gdipm ... Any statements at namespace/file scope that define variables are executed ... the order of initialization across files is unspecified. ...
    (microsoft.public.vc.language)
  • Re: C++ pushback
    ... There are all sorts of macros that use member initialization of that form. ... This does not break the code at run time, this breaks the code at compile time, and should be less painful. ... The kernel relies really _really_ heavily on such structure initializers, and breaking them would effectively break the world as far as the kernel is concerned. ... If they were not, one could simply make a base class having members outlined, and which class does not enforce type safety and is for inheritance only. ...
    (Linux-Kernel)