Thread View: de.comp.lang.c++
1 messages
1 total messages
Started by Jan Schiefer
Wed, 12 Aug 1992 00:16
Re: reference variables
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads