Default template argument problem

M

Martin

What's wrong with the following code:

template <typename T = double>
class Base
{};

class Derived : public Base
{};

Compiling it with gcc gives me "expected class name before '{' token".
Saying "public Base<double>" instead of just "public Base" works, of
course, but how come the default template argument is not being used?
 
V

Victor Bazarov

Martin said:
What's wrong with the following code:

template <typename T = double>
class Base
{};

class Derived : public Base
{};

Compiling it with gcc gives me "expected class name before '{' token".
Saying "public Base<double>" instead of just "public Base" works, of
course, but how come the default template argument is not being used?

'Base' is not a class name. It is a template-id, it has to have the
angle brackets. You can leave them empty, but they have to be present:

class Derived : public Base<>
{};

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top