EDIT: please note, as stated in @ThomasMatthews answer, it is better not to put data in a header. Please refer to his answer.
I would like to create a static const char* const array in the header file of a class. For example: const static char* ar[3] = {"asdf","qwer","ghjk"};
However I get an error.
Here is an example:
#include <iostream>
class test{
static const char* const ar[3] = {"asdf","qwer","hjkl"};
}
int main(){}
and here is the error:
static data member of type 'const char *const [3] must be initialized out of line
I'd like to know if what I am trying to do is possible. I have read Defining static const integer members in class definition and the impression I got from it was that you can only do this with int. In case this is relevant I am using a mac and my g++ version is as follows:
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
extern
declaration for the data and place the data in a source file.caused me to wonder if there is more to this
There isn't. Once youconst
the pointer as per @melpomene answer you will get another error, this time what you expect.