static array class variable “multiple definition” C++
I'm writing some code where I need to have a class variable that's a static int array. I understand that I can do this with something like this in the header file, A.h: #ifndef A_H_ #define A_H_ class A { public: static const int a[]; }; const int A::a[] = {1,2}; #endif This works just fine if I'm then including this header in only one other file, something like the following, main.cpp: #include "A.h" #include <iostream> using namespace std; int main() { A myA; cout << "0: " << myA.a[0] << endl; cout << "1: " << myA.a[1] << endl; } But suppose I need my class A to be a bit more complicated,