It's the same as the implicitly defined default constructor that you would get if you didn't declare any constructors.
It's essentially the same as S(){} except that it doesn't prevent the default constructor from being "trivial" and it can also make a difference if you value-initialize objects of this class.
1) By "you value-initialize objects" you mean using specifically curly braces for the objects, yeah?
2) The minimal version of the implementations compilers generate for defaulted special member functions are fine only for aggregates or similar simple classes. But for non-trivial classes having pointers or other stuff we can't rely on those default implementations and we should implement them explicitly. Correct?
2) The minimal version of the implementations compilers generate for defaulted special member functions are fine only for aggregates or similar simple classes. But for non-trivial classes having pointers or other stuff we can't rely on those default implementations and we should implement them explicitly. Correct?
For the default constructor I think it depends totally on the member variables and whether default initialization is what you want. For example, a default-initialized std::vector will be empty so if that is what you want then there is no problem.
You can also use default member initializers if default initialization is not what you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <vector>
struct Test
{
std::vector<int> v;
int i = 73;
Test() = default;
};
int main()
{
Test t;
std::cout << t.v.size() << "\n"; // prints "0"
std::cout << t.i << "\n"; // prints "73"
}
I have all 5 of the eBooks seeplus mentions and they are worth the effort to buy and read. There's a lot of subtle details about the language that usually get overlooked without in-depth analysis.