If I have a struct and I initialize it like so:
#include <memory>
struct MyHandle
{
std::shared_ptr<int> handle_;
};
int main()
{
MyHandle m{std::make_shared<int>(42)};
}
Is the fact that aggregate initialization of MyHandle occurs so no constructor is used to initialize object of type MyHandle?
That’s correct. Aggregate initialisation is only allowed for classes with no user-provided constructors, and (in the words of the standard, C++11 8.5.1/2), “each member is copy-initialised from the corresponding initialiser-clause”. So no constructor for
MyHandleis used, only a copy, move or conversion constructor for each member of class type.The implicit default constructor, which default-initialises each member, is used for default and value initialisation; but it can’t be used for aggregate initialisation since each member can only be initialised once.