I have tried to use C++0x initializer list as argument to a constructor call in this way:
Foo<float> foo("Foo 1", std::vector<const char *>({ "foo A", "foo B" }) );
with the constructor
Foo(const char *name, std::vector<const char *> &foos)
With this constructor the compiler complained:
error: no matching function for call to Foo<float>::Foo(
const char [5], std::vector<const char *, std::allocator<const char *> >)
note: candidates are: Foo<T>::Foo(const char *, std::vector<const char *,
std::allocator<const char *> >&) [with T = float]
However, when I've changed the constructor to
Foo(const char *name, std::vector<const char *> foos)
Everything worked as expected. Why does the first constructor not work? I thought the vector could be constructed in the place of constructor call and passed down by reference, but obviously there's some problem. Could anybody explain that?
Thanks
Btw. I am using g++ version 4.4.5
EDIT: Thanks to the correct answers below, I have found also why I can't do that.