我有一个问题,Curiously Recurring Templates 可以很好地帮助我,但我什至无法通过简单的测试。
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;
}
这会导致错误
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’
我错过了什么。
使用 g++ 4.2.1 编译
最佳答案
template<typename T, int _size, typename OutterT>
class Foo {
};
template<typename T>
class Bar : public Foo<T, 2, Bar<T> > {};
// ^^^
Bar<float> x;
由于 Bar
是一个模板,您必须提供模板参数以将其实例化为一个类。
关于c++ - 奇怪的重复模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5584088/