#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"}));
为什么initializer-list不能匹配模板构造函数?