Re: C++ design question
From: Bob Hairgrove (invalid_at_bigfoot.com)
Date: 09/30/04
- Next message: Dagfinn Reiersol: "Re: XP Requirement Analysis?"
- Previous message: Ilja Preuß: "Re: XP Requirement Analysis?"
- In reply to: H. S. Lahman: "Re: C++ design question"
- Next in thread: Simon Elliott: "Re: C++ design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Dagfinn Reiersol: "Re: XP Requirement Analysis?"
- Previous message: Ilja Preuß: "Re: XP Requirement Analysis?"
- In reply to: H. S. Lahman: "Re: C++ design question"
- Next in thread: Simon Elliott: "Re: C++ design question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|