N
Nick Keighley
I saw this in some code I'm maintaining. Is it a bad idea?
class T
{
public #:
T () i_mem(0)
{ }
T (T2 &t2) i_mem(0), t2_ref (t2)
{ }
private:
int i_mem;
T2 &t2_ref;
}
This is from memory and the real code compiles so any syntax errors
are my fault. It also had destructors, copy constructors etc.
What bothered me was the apparently uninitialised reference in the
default constructor.
If it were a pointer then would it be initialised to NULL by default?
But a reference *must* reference something?
class T
{
public #:
T () i_mem(0)
{ }
T (T2 &t2) i_mem(0), t2_ref (t2)
{ }
private:
int i_mem;
T2 &t2_ref;
}
This is from memory and the real code compiles so any syntax errors
are my fault. It also had destructors, copy constructors etc.
What bothered me was the apparently uninitialised reference in the
default constructor.
If it were a pointer then would it be initialised to NULL by default?
But a reference *must* reference something?