Curiously Recurring Templates?

294 Views Asked by At

I have a problem that Curiously Recurring Templates could help quite nicely, but I cant even get past a simple test.

template<typename T, int _size, typename OutterT>
class Foo {

};

template<typename T>
class Bar : public Foo<T, 2, Bar> {};

//typedef Bar<float> Vec2f;


int main()
{
    return 0;
}

This results in the error

foo.cpp:7: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, int _size, class OuterT> class Foo’
foo.cpp:7: error:   expected a type, got ‘Bar’

What am I missing.

compiled with g++ 4.2.1

1

There are 1 best solutions below

0
On BEST ANSWER
template<typename T, int _size, typename OutterT>
class Foo {

};

template<typename T>
class Bar : public Foo<T, 2, Bar<T> > {};
//                              ^^^

Bar<float> x;

Since Bar is a template, you must provide the template argument to instantiate it into a class.