San*_*ord 4 c++ templates parameter-passing typename
我需要将模板类作为参数传递给函数,但我可以检索函数内部的typename以初始化时态变量
该类声明如下:
template <typename Type> class ListIndex_Linked
Run Code Online (Sandbox Code Playgroud)
这里是主要类的inicialization和函数的调用
ListIndex_Linked<std::string> L;
insertion(L);
Run Code Online (Sandbox Code Playgroud)
而我正在努力做什么
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++ )
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
error: 'list' is not a template
void insertion( list<Type>& L )
^
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助
你没有宣称list是template template parameter正确的.
template <template <typename> class list, typename Type>
void insertion( list<Type>& L )
{
...
}
Run Code Online (Sandbox Code Playgroud)
参考:http://en.cppreference.com/w/cpp/language/template_parameters
| 归档时间: |
|
| 查看次数: |
2862 次 |
| 最近记录: |