I am wondering whether one can create a structure and, using the members/variables initialized in the structure as parameters, build other members. For example, I would like to make a structure:
struct myStruct {
size_t length;
std::string (&strings)[length]; // from the above variable
};
Something like this. And I understand that there are some subtleties regarding initialization order, but I'm sure that something could be worked out (constructors maybe?) to overcome that problem. Currently, the only way I've found that works is templates:
template <size_t N>
struct myStruct {
int length;
std::string (&strings)[N]; // from the template parameter
};
Keep in mind that I actually pass my length
value as a member variable in the struct, so ideally I won't need a template.
Edit:
Clarification: I need only to access the string of arrays and be able to read from them (no need to overwrite them, so const
could and should be used) as one would do with a regular array: []-based notation. I could also tolerate a change to std::array
. Anyways, I just need the strings easily accessible in a way not starkly different from regular usage. Also, it must be from a struct pointer (a.k.a. arrow operator).
Thanks much!