vla*_*don 1 c++ templates c++14
假设我有一个带int参数的模板类:
template <int Param>
class myclass
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
例如,我想实现从一个int-parametrized到另一个int参数化的强制转换函数:
template <int Param, class T>
myclass<Param> myclass_cast(const T& other)
{
// ... some logic
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能静态地确定这T是一个模板化的类myclass<N>?(我可以使用C++ 14).
T您可以推导出myclass传入的特化参数,而不是使用模板参数:
template <int Param, int Other>
myclass<Param> myclass_cast (const myclass<Other>& other)
{
}
Run Code Online (Sandbox Code Playgroud)