First attempt and everything works fine:
class Base {
public:
Base() {std::cout << "default ctor!\n"; }
};
...
Base b{};
Base b_one = {};
Another way of implementation(add explicit
):
class Base {
public:
explicit Base() {std::cout << "default ctor!\n"; }
};
...
Base b{};
Base b_one = {}; // error! Why?
I have read on cppreference that in both cases default initialization would be used and no diffences.
From list initialization:
Otherwise, If the braced-init-list is empty and T is a class type with a default constructor, value-initialization is performed.
From value initialization:
if T is a class type with no default constructor or with a user-provided or deleted default constructor, the object is default-initialized;