In cpp, we can have primitive data-types initialized as
int a(32);
How does this constructor initialisation work? Does C++ treat it as an object?
In cpp, we can have primitive data-types initialized as
int a(32);
How does this constructor initialisation work? Does C++ treat it as an object?
This is best described in:
C++03 8.5 Initializers
Para 12 & 13:
.......
The initialization that occurs in new expressions (5.3.4), static_cast expressions (5.2.9), functional notation type conversions (5.2.3), and base and member initializers (12.6.2) is called
direct-initialization and is equivalent to the formT x(a);
If T is a scalar type, then a declaration of the form
T x = { a };
is equivalent to
T x = a;
In the question the type is int
which is a scalar type.
This is so-called direct-initialization. In C++, integers are not objects and the expression that you write here is not a constructor. It just initializes a to the value of 32.