Wednesday, 21 August 2013

Why does default-initialization of reference type member result in compiler warning?

Why does default-initialization of reference type member result in
compiler warning?

I have the following code:
class A {
public:
A() { }
};
class B {
private:
const A &a;
public:
B() : a() { }
B(const A &ina) : a(ina) { }
};
Compiling results in the following:
ab.cpp: In constructor 'B::B()':
ab.cpp:11: warning: default-initialization of 'const A& B::a', which has
reference type
Why does this result in a warning and how do I fix it?

No comments:

Post a Comment