I was playing with some useless code to understand initialization of member references, and bumped into this:
struct A {};
struct B
{
B() : a()
{
}
const A& a;
};
The code above gives the following error when compiled with gcc 4.9.2:
In constructor 'B::B()':
error: value-initialization of reference type 'const A&'
B() : a()
Which I understand.
But if I use uniform initialization in B's constructor's initializer list, like so:
struct A {};
struct B
{
B() : a{}
{
}
const A& a;
};
It compiles fine.
So the question is, why does the use of uniform initialization here change the compilation result?
I also tried this with Microsoft Visual C++ 2013. It does not compile either version of the code, with the same error message:
Error 3 error C2440: 'initializing' : cannot convert from 'int' to 'const A &
You can have a quick play with it here: