I've seen these, what appear to be functions in c++ code but I have no idea what they do or what they are, they appear to do similar things to typecasts, but they don't look like typecasts, so what are they?
They look like this: int(x) where x is some numeric input, I've been looking around online but I haven't been able to find any information about them (probably because I don't know what they're called).
Any help?
This is called the "functional notation", and it is a form of explicit type conversion ("casting"). C++11, 5.2.3:
5.2.3 Explicit type conversion (functional notation)
- A simple-type-specifier (7.1.6.2) or typename-specifier (14.6) followed by a parenthesized expression-list constructs a value of the specified type given the expression list. If the expression list is a single expression, the type conversion expression is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression (5.4). If the type specified is a class type, the class type shall be complete. If the expression list specifies more than a single value, the type shall be a class with a suitably declared constructor (8.5, 12.1), and the expression T(x1, x2, ...) is equivalent in effect to the declaration T t(x1, x2, ...); for some invented temporary variable t, with the result being the value of t as a prvalue.
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