what is bool(), int(), and double() in c++/c++11? Are they true, 0 and 0.0 in c++ or c++11 standard?
Asked
Active
Viewed 158 times
0
user1899020
- 13,167
- 21
- 79
- 154
-
3Actually it is `false`, `0` and `0.0` respectively. – Cory Kramer Dec 13 '14 at 21:33
2 Answers
3
T() ia a value-initialized prvalue of type T since C++03 when value-initialization was introduced.
It is false for bool, 0 for arithmetic and nullptr for pointer-types.
Deduplicator
- 44,692
- 7
- 66
- 118
3
Quoting the C++11 FD, [expr.type.conv]/2:
The expression
T(), whereTis a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified)voidtype, creates a prvalue of the specified type, whose value is that produced by value-initializing (8.5) an object of typeT; no initialization is done for thevoid()case.
And value-initialization implies zero-initialization for scalars.
Columbo
- 60,038
- 8
- 155
- 203
-
-
How is your average Joe supposed to use a language whose specs look like a draft law on sheep breeding programmes, I wonder... – kuroi neko Dec 13 '14 at 21:48
-