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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top