Mohammed Li
Mohammed Li

Reputation: 901

Constructor error: expected ‘{’ at end of input

I am having trouble declaring a constructor from in a subclass whose superclass is created from a template.

The example code looks like this:

template <class T>
class foo{
    public:
        foo();
};

typedef foo<double> foo_double;

class bar : public foo_double
{
    bar() : foo_double();
};

int main(){
}

when I compile, I get an error:

In constructor ‘bar::bar()’:
expected ‘{’ at end of input

I am at a bit of a loss here.

Upvotes: 0

Views: 1584

Answers (3)

Andreas DM
Andreas DM

Reputation: 10998

You forgot the curly braces { }

bar() : foo_double() { }
              //     ^^^

Upvotes: 1

songyuanyao
songyuanyao

Reputation: 172894

Member initialize list can only be used with the constructor definition. So you need to define it as

bar() : foo_double() {}

And the base class will be default constructed by default, so you don't need to do it at all. Just

bar() {}

Upvotes: 6

QuestionC
QuestionC

Reputation: 10064

bar() : foo_double();

Is not a constructor.

bar() : foo_double() { }

is.

Upvotes: 1

Related Questions