I would like to have a static char array member initialized in terms of other static char array members – but the initialization is such that code is necessary. Is this possible?
class fred {
static char *a;
static char *b;
static char c[4];
}
Now a and b will have fixed values, but I want to construct c in terms of them.
EG:
fred::a = "1234"
fred::b = "ab"
strcpy(c, b);
strncat(c, a, 1);
However I can’t see anyway to initialize c, other than to make a class for the purpose which is just a char[4], with a constructor that references fred::a and fred::b, and then replace c in fred with an instance of that class – which is awkward when referencing the c char array.
Is there a better way?
Edit: Originally, I had
wilmaas a friend offred, and a static instance ofwilmadoing the initialization. I have changed the example to havedinodeclared withinfredsince the OP said he thought that would be cleaner.You can create a static instance of a class inside
fredwhose job is to initializecfor you.