【发布时间】:2018-01-30 00:39:12
【问题描述】:
调用模板函数时如何指定类型?
#include <string>
#include <utility>
#include <boost/variant.hpp>
template <typename O, typename E, template <typename, typename> class VariantType>
VariantType<O, E> f(O o)
{
return VariantType<O, E>{std::move(o)};
}
int main()
{
boost::variant<int, std::string> res =
f<int, std::string, boost::variant<int, std::string>>(17);
}
clang 报这样的错误(clang++ -Wall -std=c++11 test.cpp):
test.cpp: error: no matching function for call to 'f'
boost::variant<int, std::string> res = f<int, std::string, boost::variant<int, std::string>>(17);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'VariantType'
VariantType<O, E> f(O o)
【问题讨论】: