Declare array in C++ header and define it in cpp file?

后端 未结 7 2076
攒了一身酷
攒了一身酷 2020-12-15 04:13

This is probably a really simple thing but I\'m new to C++ so need help.

I just want to declare an array in my C++ header file like:

int lettersArr[2         


        
7条回答
  •  时光取名叫无心
    2020-12-15 04:38

    Add extern to the declaration in the header file.

    extern int lettersArr[26];
    

    (Also, unless you plan to change the array, consider also adding const.)

    The definition must have a type. Add int (or const int):

    int lettersArr[26] = { letA, /*...*/ };
    

提交回复
热议问题