I want to have a method that takes a list as a parameter but this list should have default values, here is an invalid example for what I need:
void myFunc(std::list<CString> const & myList = std::list<CString>({"Val1", "Val2", "Val3"}));
When I try to use it I get
Error C2143: syntax error: missing ')' before '{'
Micrsoft Visual Studio 2010 does not support std::initializer_list
. When you do
std::list<CString>({"Val1", "Val2", "Val3"})
You attempt to initialize the std::list
using it's std::initializer_list
constructor. Since MSVS 2010 doesn't support that you can call it.
One thing you can do is write a function that creates and initializes a list like
std::list<CString> default_list()
{
std::list<CString> temp;
temp.push_back("Val1");
temp.push_back("Val2");
temp.push_back("Val3");
return temp;
}
And then you can use that like
void myFunc(std::list<CString> const & myList = default_list());