I've seen this in a lot of example code:
but I don't quite understand why you would default it to void?Code:template <typename T=void>
You can create a void* variable, but not a void variable, so what's going on?
Printable View
I've seen this in a lot of example code:
but I don't quite understand why you would default it to void?Code:template <typename T=void>
You can create a void* variable, but not a void variable, so what's going on?
What about:
Code:class TemplateClass {
T *test;
};
The only thing I could imagine is when T is declared as a variable like that, but then why use void* if you're using a template? Aren't void* pointers more useful in C than in C++?
Hmm brewbuck may have a point. But I'd rather do that something like this:
Rather than defaulting to void and declaring a variable that wouldn't be allowed.Code:template<typename T> class SomeClass;
template<>
class SomeClass<AllowedType1> {
};
But, true, void pointers can often be avoided in C++. So the system you read it at would probably be badly designed anyway.