【发布时间】:2016-02-04 09:51:50
【问题描述】:
阅读了关于 SO 的几个答案(例如 here 和 here),我想出了在模板库中调用函数模板的两种常用替代方法:
template<typename T>
struct Base
{
template<int N>
auto get() const
{
return N;
}
};
template<typename T>
struct Derived : public Base<T>
{
//first alternative
auto f0() const { return this-> template get<0>(); }
//second alternative
auto f1() const { return Base<T>::template get<1>(); }
};
但是对于非模板函数,是否也有与using Base<T>::foo 声明等效的方法?也许像
template<int N>
using Base<T>::template get<N>; //does not compile in gcc
【问题讨论】:
-
@T.C.所以它不是标准的一部分,我的部分(!)答案只显示了 VS2015 提供的扩展?
标签: c++ templates inheritance