b3n*_*nj1 3 c++ parameters templates clang c++11
嗨,我正在尝试使我的代码在clang 3.2-9下编译,这是我无法编译的简化示例:
template<template <class>class Derived, typename Type>
class Foo
{
public:
Foo(){}
};
template<typename Type>
class Bar
: public Foo<Bar, Type>
{
public:
Bar()
: Foo<Bar, Type>()
{}
};
int main()
{
Bar<int> toto;
}
Run Code Online (Sandbox Code Playgroud)
这是clang告诉我的错误:
test.cpp:14:19: error: template argument for template template parameter must be a class template
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected class member or base class name
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected '{' or ','
3 errors generated.
Run Code Online (Sandbox Code Playgroud)
它在gcc 4.7.2下编译没有任何问题.我无法使用正确的语法使其在clang下工作.请有人帮帮我,我有点卡住了......
只需使用类模板的完全限定名称:
template<template <class> class Derived, typename Type>
class Foo
{
public:
Foo(){}
};
template<typename Type>
class Bar
: public Foo<::Bar, Type>
// ^^^^^
{
public:
Bar()
: Foo<::Bar, Type>()
// ^^^^^
{}
};
int main()
{
Bar<int> toto;
}
Run Code Online (Sandbox Code Playgroud)
问题在于,在内部Bar,名称Bar是指类本身,即类模板(即)的实例化,而不是模板本身.BarBar<Type>
你可以在这里看到这个例子.
| 归档时间: |
|
| 查看次数: |
829 次 |
| 最近记录: |