I understand that I want the const array in the class namespace in C ++ I could not:
class c { private: struct p { int a; int b; }; static const p pp[2]; }; const c::p pp[2] = { {1,1},{2,2} }; int main(void) { class c; return 0; }
I have to do:
class c { public: struct p { int a; int b; }; static const p pp[2]; }; const c::p pp[2] = { {1,1},{2,2} }; int main(void) { class c; return 0; }
But this requires that p and pp be publicly accessible when I want them to be private. Is there no way in C ++ to initialize private static arrays?
EDIT: ------------------- Thanks for the answers. In addition, I want this class to be a library, only header files, for use in the main project. Enabling the following initializer leads to a "multiple definition" of errors when including multiple files.
const c::pc::pp[2] = { {1,1},{2,2} };
How can i solve this?
source share