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?
I want to make an array static and also want to reference it in
Share
Remove the
static. Just have theint array[100] = {...};in one .cpp file, and haveextern int array[100];in the header file.staticin this context means that other translation units can’t see it. That obviously conflicts with theexterndirective.