【发布时间】:2014-02-05 05:20:02
【问题描述】:
我正在尝试使用模板模板参数,类似于 here 和 here(以及许多其他地方)所做的。
#include <vector>
template<template<class> class A, class B>
void f(A<B> &value) {
}
int main() {
std::vector<int> value;
f<std::vector, int>(value);
}
但是
$ g++-4.8 -std=c++0x base64.cpp
base64.cpp: In function ‘int main()’:
base64.cpp:9:23: error: no matching function for call to ‘f(std::vector<int>&)’
f<std::vector, int>(value);
^
base64.cpp:9:23: note: candidate is:
base64.cpp:4:6: note: template<template<class> class H, class S> void f(const H<S>&)
void f(H<S> &value) {
我错过了什么?
【问题讨论】:
-
std::vector有多个模板参数,如果可以推断出模板参数(此处可以),则不应明确指定模板参数。 -
直接拨打
f(v)可以吗? -
@anthony-arnold,不。
note: template argument deduction/substitution failed: error: wrong number of template arguments (2, should be 1) -
@chris,去掉参数还是不行。
标签: c++ templates c++11 template-meta-programming