I work with a following class:
class TheirClassA
{
public:
double GetP() const {return fP;}; // get p
private:
double fP; // p
};
There are of course also constructors/destructor/etc which I'm not including for the sake of brevity. This class is given to me in the data I receive, so I cannot modify its code or anything.
Now in my code, I want to have a class, let's say MyClass, which reads TheirClassA contents and distributes them further. Sort of like an interpreter of the TheirClassA input. In my code, I wish to work with this interpreter, i.e. get data from MyClass instead of TheirClassA. Hopefully I'm still being clear. Something like:
TheirClassA *input = (TheirClassA*)Data->At(i);
MyClass *interpreter = new MyClass(input);
double P = interpreter->AccessP();
But what is the best way to go about this? A simple way would be to get the values from the input and save it as data members of a MyClass instance. However, some of these members might be Double, or even strings, so I don't want to waste a lot of resources copying/storing values (I will be looping over millions of instances of the input class).
Is there a way for me to somehow define the interpreter MyClass in such a way that its members point at the addresses of the input's members, instead of holding the values? So that the the MyClass::AccessP() looks at the address of the TheirClassA::fP and passes its value?
Looking very much forward to suggested solutions! Thanks in advance.
P.S. Apparently such thing is called a 'wrapper'?