I understand if I want a const array in a class namespace in C++ I cannot do:
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 must 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 "p" and "pp" to be public, when I want them to be private. Is there no way in C++ to initialise private static arrays?
EDIT: ------------------- Thanks for the answers. In addition I want this class to be a library, header files only, for use by a main project. Including the following initialiser results in " multiple definition of " errors when included by multiple files.
const c::p c::pp[2] = { {1,1},{2,2} };
How can I solve this?