Chapter 42. Variable Initialization—Or is it?
This first problem highlights the importance of understanding what you write. Here we have four simple lines of code, no two of which mean the same thing, even though the syntax varies only slightly.
What is the difference, if any, between the following? (
T stands for any class type.)
T t; T t(); T t(u); T t = u;
This puzzle demonstrates the difference between three kinds of initialization: default initialization, direct initialization, and copy initialization. It also contains one red herring that isn't initialization at all. Let's consider the cases one by one.
This is default ...