I'm bringing some old unmaintained software up to date, and I've noticed a peculiar pattern that I haven't been able to adequately explain.
The code in question is written in C++. Normally when I see data members, they exist inside the class declaration as public or private members. In the code I'm currently working with, nearly every class stores the data members inside an additional struct, like so:
struct MyClassData {
int foo;
int bar;
};
class MyClass {
MyClassData classData;
public:
void doFoo();
void doBar();
void doBaz();
};
Unfortunately the original maintainer of this code is unreachable. Every single class (there's about a hundred of them) all do this though. I can't figure out why, since the MyClassData struct is never used anywhere other then at the top of the class declaration.
Is there any particular reason why someone would choose to layout their C++ classes in this manner? I understand there are reasons for wanting and using a struct as a data member, but what I don't understand is why you'd want to stuff all your data members inside a single struct like this, and never doing anything else with that structure. I suppose it might remove any ambiguity as to what you're accessing within your methods and how (since everything will need to go through classData first), but beyond that, I dunno. I'm wondering if there's a technical reason for this that I haven't yet uncovered.