Topic: Initialization of references.
Author: alindbac@sw.seisy.abb.se (Anders Lindback)
Date: 1996/04/14 Raw View
The september 95 Working draft 8.3.1 says:
"A reference shall be initialized to refer to a valid object or function."
What is a valid object ? I can't find a good decription of that in
the draft. Is it:
1. An object that has storage.
2. An object which constructor has executed.
3. A typo ?
4. An out-of-date sentence in the draft.
5. None of the above ?
Example code from gnu.g++.help:
>#include <iostream.h>
>
>class Foo
>{
>public:
> Foo (int size_arg = 0) : size (my_size), my_size (size_arg),
> values (new double [size]) {}>
~Foo () { delete values; }
> int const& size;
>private:
> int my_size;
> double* values;
>};
Is this code correct C++ code or not ?
Or must one change the order of the member variables in the
class so that my_size is before size and get to be intialized
first ?
And what will happend if they not are integers but actuall classes
with constructors ?
Anders
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]