Reputation:
I have a struct called member
. Within member
I have a std::string
array called months
that I would like to initialize to default values. This is how I am doing it currently:
template <typenameT>
struct member
{
std::string months[12];
std::string name;
T hours_worked[12];
T dues[12];
member() : months{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} {};
};
However, whenever I compile I get this warning message:
warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
How can I do the initialization properly and get rid of this error message?
Edit:
I should of made my question more clear. I need compile this program on a older compiler and the -std=c++0x
flag option will not be available to me. How can I do this correctly without using the flag.
Upvotes: 1
Views: 629
Reputation: 10081
It tells you in the warning. Try adding -std=c++0x
to your g++ arguments. If you want to be able to use this on an older compiler then you can't use initialiser lists the way you are doing.
Instead you could change member() to be something like
member()
{
months[0] = "January";
months[1] = "February";
...//etc
}
Upvotes: 1