【发布时间】:2018-11-07 10:29:32
【问题描述】:
#include <iostream>
class Foo
{
public:
template <typename Container>
Foo (const Container & args)
{
for (auto arg : args)
std::cout << "ARG(" << arg << ")\n";
}
};
int main ()
{
Foo foo ({"foo", "bar", "baz"});
}
错误(使用g++ -std=c++17)是
error: no matching function for call to ‘Foo::Foo(<brace-enclosed initializer list>)’
这行得通
Foo foo (std::vector<const char*> ({"foo", "bar", "baz"}));
为什么初始化列表不能匹配模板构造函数?
【问题讨论】:
标签: c++ templates c++17 initializer-list template-argument-deduction