I have read in Dr. Bjarne Stroustrup Book "The C++ Programming Language" 3rd edition that built in types have also constructors in C++ in section 10.4.2.
But then the following link says that POD types can't have constructors:
http://www.parashift.com/c++-faq-lite/pod-types.html
Which is true? Do primitive types have also constructors in C++?
What Bjarne means is that you can write int(56)
or even int()
to construct an integer. What the links means is that a struct/class is only a POD if it does not have a constructor declared. So Bjarne talks about primitive non-struct types and the link talks about structs/classes so the two sources can coexist without contradicting each other.
Here is part of the definition from the link:
a POD type's non-static data members must be public and can be of any of these types
Of course, this can only hold for structs. An int
has no "data members". So although the link never mentions it directly, it only refers to structs and classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With