Initializing a static const array of const strings in C++

First of all, you need an array, not a pointer.

static const char * const days[] = {"mon", "tue", "wed", "thur",
                                       "fri", "sat", "sun"};

Second of all, you can’t initialize that directly inside the class definition. Inside the class definition, leave only this:

static const char * const days[]; //declaration

Then, in the .cpp file, write the definition

const char * const Week::days[] = {"mon", "tue", "wed", "thur",
                                       "fri", "sat", "sun"};

Update for C++11
Now you can initialize members directly in the class definition:

const char * const days[] = {"mon", "tue", "wed", "thur",
                                       "fri", "sat", "sun"};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)