C++: use array of strings wrapped in namespace?
- by John D.
I got the following code, wishing to wrap a group of strings nicely in a namespace:
namespace msgs {
const int arr_sz = 3;
const char *msg[arr_sz] = {"blank", "blank", "blank" };
msg[0] = "Welcome, lets start by getting a little info from you!\n";
msg[1] = "Alright, bla bla bla..";
msg[2] = "etc.";
}
The code inside works nicely inside a function, but I don't know how to return an array from it. The namespace idea LOOKS fine, but it returns on the last three lines:
error: expected constructor, destructor, or type conversion before ‘=’ token
Why can't I define the array inside a namespace, do I need to do something first?
It's nice because I can call it like printf(msgs::msg[1]) etc. I want to do this I just can't wrap my head around what's wrong :(