首先我學習了模板模板參數,我開始想知道如果我有一個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
嘗試矢量:: VALUE_TYPE - 沒有需要把它複雜化。 – erenon