I have a list<string> myList as a private attribute of my class. The content of this list is known at compile time and is constant. Is there any compact way (in C++03) to initialize its value? I can only think of this:
MyClass::MyClass(){
myList.push_back(string("str1"));
myList.push_back(string("str2"));
myList.push_back(string("str3"));
etc.
}
I would like something like this:
MyClass::MyClass():list("str1","str2","str3",etc.){
}
This code is not fully tested, but I would suggest this if you can’t use the new and cool stuff in C++11:
Usage:
EDIT
See full example at http://ideone.com/LWGRCc