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

后端 未结 7 2058
攒了一身酷
攒了一身酷 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:44

    You can do it this way:

    in header

    extern int lettersArr[26];
    

    in .cpp

    int lettersArr[26] = { letA, letB, letC, letD, letE, letF, letG, letH,
            letI, letJ, letK, letL, letM, letN, letO, letP, letQ, letR, letS,
            letT, letU, letV, letW, letX, letY, letZ };
    
    0 讨论(0)
提交回复
热议问题