Why can void be supplied to template argument lists but not be allowed to be a type of a variable in C++

Viewed 14

I can write void as a default template argument like this:

template<typename T = void>
class Foo {};

But I cannot declare a variable of type void like this: void foo; What kind of type is void if it can be supplied to templates but you can't declare void variables? What is the point of void as a default template argument if you can never use it for variables? Does it have any other uses?

1 Answers

If u want to create a variable that has null value u can simply write it as:

T={}; T=0;

As u like. But u cant assign it like u were trying to. For the builtin functions or syntax cannot be used other than their functionality be it any language.

Related