C++ 奇怪的重复模板?
我有一个问题,奇怪的重复模板可以很好地帮助我,但我甚至不能通过一个简单的测试C++ 奇怪的重复模板?,c++,templates,crtp,f-bounded-polymorphism,C++,Templates,Crtp,F Bounded Polymorphism,我有一个问题,奇怪的重复模板可以很好地帮助我,但我甚至不能通过一个简单的测试 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; }
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{};
//typedef-Bar-Vec2f;
int main()
{
返回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’
foo.cpp:7:错误:“模板类foo”的模板参数列表中参数3的类型/值不匹配
foo.cpp:7:错误:应为类型,但得到“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;
福班{
};
模板
类栏:公共Foo{};
// ^^^
条形图x;
由于Bar
是一个模板,因此必须提供模板参数以将其实例化为类