I want to make an array static and also want to reference it in the other translation unit. Then I define it as static int array[100] = {...}, and declare it in other translation unit as extern int array[]. But the compiler tells me that the storage class of static and extern conflict with each other, how could I pass it and still reach my goal?
Remove the static. Just have the int array[100] = {...}; in one .cpp file, and have extern int array[100]; in the header file.
static in this context means that other translation units can't see it. That obviously conflicts with the extern directive.
static in file scope is pretty much a declare-private directive to the assembler. It is most certainly different than static in class or function scope.
E.g. in zlib, #define LOCAL static is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With