C++11 allows in-class initialization:
struct Foo{
std::vector v{3}; // vector of 3 empty strings
};
If we wanted to
Default member initializers work with =
as well. So
struct Foo{
std::vector<int> v = std::vector<int>(3);
};
Will do it. Though obviously, a major caveat is the fact that we are repeating the type name here.
We can alleviate it somewhat with decltype
:
struct Foo{
std::vector<int> v = decltype(v)(3);
};
But that still has us naming things twice.