views:

138

answers:

2

Does VC++ not support default template parameters arguments? This simple code:

template <typename T=int>
class X
{
};

X x;

gives me an 'error C2955: 'X' : use of class template requires template argument list'. No complaints about the template declaration, however.

What am I missing here? Some compiler switch maybe?

+5  A: 

I think you still have to specify an empty template list, or use a typedef:

template <typename T=int>
class X
{
};

X<> x;

typedef X<> XX;
XX x;
1800 INFORMATION
A: 

Your question has already been answered very well. However, I want to point out that, whenever you ask yourself whether it's you or the compiler, take a code snipped to Comeau's online compiler. Comeau is widely acknowledged as the most standard-conforming C++ compiler around and has excellent error messages.

BTW, surprisingly the compiler doesn't cost much, so if you want the convenience to have it on your machine, the price shouldn't be in your way.

sbi