I have a lot of questions in mind, but this topic seems to be
complicated, so I will content myself with the following only.
1. Why does "A a = A();" initialize x to 0, but "A a;" doesn't in
local scope? Are you saying this is purposely designed so that the
programmer can choose not to initialize variables for the sake of
optimization?
I don't think it was intentional, per se. The idea is that if
you write A(), you get initialization, and otherwise you don't.
The problem with local scope is, of course, that "A a()" is not
a variable defintion, but a function declaration.
2. What exactly is the difference between:
I always thought they were the same, but apparently not.
Not really. In this case, the difference is just what I have
said; in one case, you get zero initialization, in the other
not. If there is a user defined constructor, they are both
identical. More generally, however:
A a( someInit ) ;
and
A a = someInit ;
are not identical. The first is direct initialization; the
compiler tries to find a constructor which can be called using
someInit. The second is copy initialization; the compiler tries
to *convert* someInit to A, and initializes the variable using
the copy constructor. (In fact, the compiler is allowed to
optimize out the use of the copy constructor, *provided* the
program would be legal if it didn't. If the constructor of A
which takes a someInit is explicit, for example, the second form
won't compile, or if the conversion of someInit to A requires
two user defined conversions.)