Reputation: 4508
I'm not new to C++ but I haven't coded much using it either. I have recently come across code that has "<>" in the variable declaration. Here is how it looks
MyClass<> *instancePtr;
I'm sure it has something to do with templates, but I can't really find anything online. Can anyone help me out with this? What does the code mean?
Any help is appreciated, Thanks.
Upvotes: 2
Views: 108
Reputation: 320421
It means that MyClass
is a template and that MyClass
template declaration supplies default arguments for all template parameters.
For example, if the template is declared as follows
template <typename T = int, typename U = double, int N = 5> class MyClass {
...
};
then
MyClass<> *instancePtr;
is equivalent to
MyClass<int, double, 5> *instancePtr;
Note that when you are referring to a template class, the <>
is always required, even if there's nothing between the <>
. You cannot just say
MyClass *instancePtr;
even if all template parameters have default arguments. (Some older compilers supported this incorrect usage.)
Upvotes: 10