简体   繁体   中英

How to create a static const array of const char*

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.

You wrote const const instead of static const char* const values[]; (where you define the pointer and the underlying values as const )

Also, you need to initialize it:

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

Try

static const char* const values[];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM