Article View: de.comp.lang.c++
Article #27Re: reference variables
From: Jan Schiefer
Date: Wed, 12 Aug 1992 00:16
Date: Wed, 12 Aug 1992 00:16
27 lines
1167 bytes
1167 bytes
tmorgan@andromeda.rutgers.edu (Why? Only I Can Be Me) writes:
> I do something similar to the following:
> class X {
> int &var ;
> public:
> constructor that initializes var...doesn't work.
> destructor
> rest of functions
> .
} ;
Ah! Now I understand the problem. You may not initialize the reference in the
constructor, you have to use a constructor-initializer instead. In the above
example your constructor would have to be declared as
X(int& i) : var(i) { /* do what an X-constructor does */ };
The ARM mentions this in section 12.6.2 and says it is the only way to
initialize nonstatic const and reference members.
Good luck,
Jan
--
Jan Schiefer, DL5UE, jan@nasobem.stgt.sub.org
"Oracle et laboracle!" - Fritz Hohl
Technical Details
Message-ID:
<4598.920812@nasobem.stgt.sub.org>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!jvnc.net!gmd.de!Germany.EU.net!rz.uni-hildesheim.de!agsc!nadia!delos!nasobem!janShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!jvnc.net!gmd.de!Germany.EU.net!rz.uni-hildesheim.de!agsc!nadia!delos!nasobem!jan From: jan@nasobem.stgt.sub.org (Jan Schiefer) Newsgroups: de.comp.lang.c++ Subject: Re: reference variables Message-ID: <4598.920812@nasobem.stgt.sub.org> Date: Wed, 12 Aug 92 0:16:39 GMT Distribution: world Lines: 27