11

I tried the following line:

static const const char* values[]; 

But I get the following warning on VC++ warning C4114:

same type qualifier used more than once.

What is the correct declaration? The goal is to create an immutable array of c strings.

4

2 回答 2

22

您写const const而不是static const char* const values[];(您将指针和基础值定义为const

此外,您需要对其进行初始化:

static const char* const values[] = {"string one", "string two"};

于 2012-06-12T14:07:38.243 回答
5

Try

static const char* const values[];

The idea is to put the two consts on either side of *: the left belongs to char (constant character), the right belongs to char* (constant pointer-to-character)

于 2012-06-12T14:05:34.427 回答