A default member initialisation needs to reference an existing constructor, no matter if it is ever used or not. So, looking at a struct Foo which has no default constructor:
struct Foo{
Foo(int x) : x_(x){}
int x_;
};
It is clear that the following wouldn't work, and leads to a compilation error:
class Bar0{
Foo foo = Foo(); #constructor Foo() doesn't exist
Bar0() : foo(0){}
}
But, it is a different story with std::unique_ptr and std::make_unique:
class Bar1{
unique_ptr<Foo> foo = make_unique<Foo>(); #compiler doesn't complain
Bar1() : foo(make_unique<Foo>(0)){}
}
This is puzzling, as the compilation fails as soon as Bar1 contains one constructor where foo is not in the initialiser list.
I can confirm this to be true of MSVC12. Could it be a compiler bug?
make_uniqueis part of C++14 and already supported in VC. I have lifted this code directly from a Visual Studio Project and it is the only thing contained in it, apart from an empty main function. The typo must have slipped in during editing. If you see any other ways to improve this question, please tell me.