如何在模板基类中调用模板成员函数?
在基类中调用非模板化成员函数时,可以将其名称用
using
导入到派生类中,然后使用它。这也适用于基类中的模板成员函数吗?
只是使用using
它不起作用(使用g ++ - snapshot-20110219 -std = c ++ 0x):
template <typename T>
struct A {
template <typename T2> void f() { }
};
template <typename T>
struct B : A<T> {
using A<T>::f;
template <typename T2> void g() {
// g++ throws an error for the following line: expected primary expression before `>`
f<T2>();
}
};
int main() {
B<float> b;
b.g<int>();
}
我知道明确地为基类添加前缀
A<T>::template f<T2>();
工作正常,但问题是:是否有可能没有和使用简单的使用声明(就像f
不是模板功能的情况一样)?
万一这是不可能的,有谁知道为什么?
没有找到相关结果
已邀请:
2 个回复
峨躬坎抬焚
那样做
为什么
不适用于模板相关的模板函数非常简单 - 语法不允许在该上下文中使用所需的关键字。
誓猎贰
要么: