I want to declare a char array in a struct and initialize it when it is declared. I compiled it on g++ and VS2010 compilers. g++ could compile the following code but VS2010 couldn't. VS2010 has error. From C++ primer, const static type data could be initialized when it is declared in a struct/class. But when I use it for the OPName array, both compilers reports errors. I can only use const on g++ to achieve that. Why does it happen? What is the valid way to initialize array variables, like my example (i.e., char array), when they are declared in a struct/class?
Here is the code (.c file):
typedef struct OPMap {
const char OPName[27][6] = {"SW", "LW", // 2
"J", "BEQ", "BNE", "BGEZ", "BGTZ", "BLEZ", "BLTZ", // 7
"ADDI", "ADDIU", // 2
"BREAK", // 1
"SLT", "SLTI", "SLTU", // 3
"SLL", "SRL", "SRA", // 3
"SUB", "SUBU", "ADD", "ADDU", // 4
"AND", "OR", "XOR", "NOR", // 4
"NOP"}; // 1
unsigned int op[8][8];
unsigned int op_TLB[4][8];
unsigned int op_R[8][8];
const unsigned int NOP = 0x00000000;
OPMap() {
//......
}
} Map;