Initializing a static const char* array

2019-04-24 16:21发布

here is my question I have this in my .h file

static const char *Title[];

How do I initialize the array in my .C file the array to lets say "first", "second", "third"

2条回答
Emotional °昔
2楼-- · 2019-04-24 16:52

static const char* Title[] = { "first", "second", "third" };

Check out this little blurb on initialization. Why do you want to do it in separate files? You'll have to do externs.

// in .h
extern const char* Title[];

// in .c
const char* Title[] = { "first", "second" };
查看更多
我想做一个坏孩纸
3楼-- · 2019-04-24 16:54

If it's C++ you could wrap this array about a class and create a static instance of it.

查看更多
登录 后发表回答