First, let me apologize for calling you ungrateful, in another thread. I
was angry. I stand by the rest (that your attacks were silly, and that
they really annoyed me, and so forth), because that was either objective
or reporting how I felt, but assigning motives and deducing
characteristics of people is Just Wrong. I did it out of anger but it
was still wrong of me. I had no basis for that, it was not an
evaluation, it was just very ugly name calling, lashing out. I'm sorry.
Now regarding what you write here, I agree with you in principle, that
this is a good way to think about it, a good conceptual model.
But it's worth being aware that this model, of the default constructor
being called, either a user-defined one or one generated by the
compiler, breaks down in a certain case, as illustrated below:
------------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
struct S
{
int score;
string name;
};
auto operator<<( ostream& stream, S const& o )
-> ostream&
{ return stream << "{" <<
o.name << ", " << o.score << "}"; }
auto main() -> int
{
S a; // Default initialization
S b{}; // Value initialization
cout << a << endl;
cout << b << endl;
}
------------------------------------------------------------------------
Results in Windows 10 using MinGW g++ 6.3.0 and Visual C++ 2017:
------------------------------------------------------------------------
[H:\forums\clc++\020 vaue init versus default init]
> g++ initializations.cpp
[H:\forums\clc++\020 vaue init versus default init]
> a
{, 65535}
{, 0}
[H:\forums\clc++\020 vaue init versus default init]
> cl initializations.cpp /Feb
initializations.cpp
[H:\forums\clc++\020 vaue init versus default init]
> b
{, 15726820}
{, 0}
[H:\forums\clc++\020 vaue init versus default init]
> _
------------------------------------------------------------------------
The funny `a.score` values stem from default initialization. It leaves
that member indeterminate. Value initialization zeroes it.
Now you wrote nothing about value initialization, but it's clear from
the difference that either value initialization uses a default
constructor that's not the one that default initialization uses, or one
or both of them doesn't actually call a constructor with a single
well-defined effect, or both compilers above are non-conforming.
In C++98 there was no value initialization so one had the indeterminate
value in both the `S a;` case and e.g. the `S* p = new S();` case.
Andrew Koenig then fixed this partially by proposing value
initialization, which was included in C++03. This was the only really
new thing in C++03, which otherwise was just Technical Corrigendum 1,
TC1, a bug-fix of C++98. But if we view it as a fix of a design level
bug (with the “design” the design of C++) it was also just a fix. ;-)
Cheers!, and again, sorry for that name calling,
- Alf