Click to See Complete Forum and Search --> : Default arguments for class template parameters


HighCommander4
November 27th, 2004, 02:29 PM
Is it possible to have a class that has template parameters, all of which have default values, so that you can use that class name without specifying a template parameter?

My compiler seems to object to the following code

template <typename T = int>
class A
{
...
};

int main()
{
...
A x;
...
return 0;
}

Andreas Masur
November 27th, 2004, 03:05 PM
Well...in general you can omit template arguments which does have a default argument, however, even if all template arguments have a default value, the angle brackets MUST be provided (even if they are empty)...thus...

A<> x;