According to http://en.cppreference.com/w/cpp/language/explicit_cast, C-style cast and functional cast are equivalent. However, see the following example:
#include <array>
int main() {
std::array<int, 3> arr{};
(void)arr;
//void(arr);
}
While (void)arr compiles, void(arr) does not. What have I missed?
If there are no ambiguities (e.g. other functions with the same name, macros..) involved, the following code declares and defines two int
variables
int a = 22;
int (b) = 33;
thus you're trying to create a void variable type (with an existing name).
And that's wrong because:
You're trying to create a void variable
You're trying to use an existing name for another variable in the same scope
While void(arr)
is usually the same as (void)arr
, in this context it is a definition, and you are trying to create a variable called arr
of type void
, which isn't allowed.
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