【发布时间】:2017-08-24 22:17:44
【问题描述】:
首先我在学习模板模板参数,我开始想知道我是否有一个vector<vector<int>>,是否可以制作一个从那里提取类型int 的模板。
但是,在尝试构建示例的过程中,我什至无法让单级模板参数模板函数起作用!
#include <iostream>
#include <vector>
template<
template<class> class C2,
class I
>
void for_2d(const C2<I>& container)
{
for( auto j : container ){
std::cout << j;
}
}
int main() {
std::vector<int> cont;
for_2d(cont);
return 0;
}
这会产生:
17 : <source>:17:5: error: no matching function for call to 'for_2d'
for_2d(cont);
^~~~~~
8 : <source>:8:6: note: candidate template ignored: substitution failure : template template argument has different template parameters than its corresponding template template parameter
void for_2d(const C2<I>& container)
^
1 error generated.
Compiler exited with result code 1
【问题讨论】:
-
试试 vector::value_type - 无需复杂化。
标签: c++ c++11 templates typetraits template-templates