In a large C++ project, I'm changing a struct to a class, but trying to minimise changes to any code that use the struct to make it easy to revert or reapply the change.
The struct is declared as follows:
struct tParsing {
char* elements[23];
};
And here's the current version of the class declaration (note I've shown the elements
method body in the declaration for clarity, but the real code has that separately in a CPP file):
class tParsing
{
public:
tParsing();
~tParsing();
void clear();
char* elements(int index) {
if (index < 0 || index > 22) return NULL;
return fElements[index];
};
private:
char* fElements[23];
};
Other parts of the code have many cases like the following to get one element from the struct:
parsingInstance->elements[0]
To meet my goal of minimising changes, is there any way to make the class so that the elements
method can be called using array notation (instead of parentheses) to pass the index argument, so code like the line above will work regardless of whether tParsing
is a struct or a class?