我需要将模板类作为参数传递给函数,但我可以在函数内检索类型名称以初始化时间变量
类声明如下:
template <typename Type> class ListIndex_Linked
这里是类在main中的初始化和函数的调用
ListIndex_Linked<std::string> L;
insertion(L);
以及我正在尝试做的事情
template <class list <typename Type>>
void insertion( list<Type>& L )
{
Type& temp = L.get(0);
{
int max = L.numElem();
for ( int i = 1, ; i < max; i++ )
{
}
}
}
但是我得到这个错误:
error: 'list' is not a template
void insertion( list<Type>& L )
^
在此先感谢您的帮助
最佳答案
您没有将 list
正确声明为 template 模板参数
。
template <template <typename> class list, typename Type>
void insertion( list<Type>& L )
{
...
}
引用:http://en.cppreference.com/w/cpp/language/template_parameters
关于C++ 将模板类型名类作为函数参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30296381/