Here are the various categories of behavior:
f(x++) + g(x++)
wchar_t
, char_16t
, etc)
*
, []
, &
)
int f(int x) { int y; … }
class C {
…
private:
int x;
};
int x;
int f() {…}
for (int i = 0; i < n; i++)
…
X a1 {v}
int i {17};
int a[] {1, 2, 3, 4};
Person p {1001, "Gerald", "Weiss"};
{…}
is an actual type (actually a class template from the STL) …
std::initializer_list
int i {2.0}; // compilation error on narrowing from double to int
X a2 = {v};
int arr[] = {1, 2, 3, 4};
Person p = {1001, "Gerald", "Weiss"};
X a3 = v;
int x = 17;
Counter c = 12;
X a4(v);
Person p(1001, "Gerald", "Weiss");
new
)
remain uninitialized unless they are of a class type with a default constructor.
new
/delete
using intp = int *; using uchar = unsigned char;
using Speed = int;
int *ip1, ip2; // ip2 is NOT a pointer int a[10], b; // b is NOT an array
phone_book
rather than phone_vector
count
rather than icount
(integer count)
number_of_elements
over
camel case, e.g., numberOfElements
auto
, you don't want
unintended conversions which can happen with the other initializers.
auto
will deduce the type to be std::initializer_list
auto i {17}; // compiler will incorrectly deducei
to be of typestd::initializer_list<int>
auto j = 17; // compiler will correctly deducej
to be of typeint