I was given a piece of code that uses void()
as an argument. The code doesn't compile... obviously?
Can we instantiate anything of type void
? I believed the answer was no, with the exception of a void*
. For example:
- Writing the function
void askVoid(void param) {}
errors:
A parameter may not have
void
type
- Writing the function
void askNaught() {}
and calling it with askNaught(void())` errors:
error C2660:
takeNaught
: function does not take 1 arguments
- Writing the templatized function
template <typename T> void takeGeneric(T param) {}
and calling it withtakeGeneric(void())
errors:
error C2893: Failed to specialize function template
void takeGeneric(T)
- Declaring
void voidType
errors:
Incomplete type is not allowed
- Declaring
auto autoVoid = void()
errors:
Cannot deduce
auto
type
- Declaring
void* voidPtr
works fine, butremove_pointer_t<decltype(voidPtr)> decltypeVoid
errors:
error C2182:
decltypeVoid
: illegal use of typevoid
That's it, right? There is no place for void()
in C++ is there? This is just bad code I've been given, right?