This one has me stumped. What I'm trying to do is get a reference variable in a wrapper class to point to a struct object in the class it wraps so that any setting of variables in the struct from other classes that use the wrapper class, actually are set in the wrapped class not the wrappper class. To do this I tried to simply create a reference in the wrap class to the struct in the wrapped class like
class CClassWrap
{
CClass::plot_type& PlotArgs;
}
and then init PlotArgs
CClassWrap::InitWrap( CClass AppIfx )
{
PlotArgs = AppIfx.PlotArgs;
}
I just want PlotArgs to point to the wrapped class' PlotArgs so that when PlotArgs is accessed from say this
class StudiesBase:public CClassWrap
{
//12 should show up in CClass because PlotArgs in CClassWrap points to the PlotArgs on CClass.
PlotArgs.value = 12;
}
12 shows up in the wrapped classes version of PlotArgs. To do this I tried setting a reference defined in the .h file as follows
#include "CClass.h"
class CClassWrap
{
//PlotArgs is a struct with a few vars in it (int, long, etc.) that exists in CClass
CClass::plot_type& PlotArgs;
}
CClassWrap is inherited in another class, call it StudiesBase
class StudiesBase:: public CClassWrap
{
etc...
}
When this is compiled, an error is given saying no default ctor exists for CClassWrap. So I add a Ctor
such that CClassWrap now looks like
class CClassWrap
{
public:
CClassWrap();
public:
//PlotArgs is a struct with a few vars in it (int, long, etc.) that exists in CClass
CClass::plot_type& PlotArgs;
}
This generates an error C2758 saying that PlotArgs is not inititlaized.
So in the ctor for ClassWrap I try to init it.
PlotArgs = AppIfx.PlotArgs;
where AppIfx is set at runtime as a pointer to the CClass object. The compiler doesn't like that either with error C2758 variable must be initialzied in constructor base/member initializer list etc...
If it appears that I'm trying to do something that I'm totally clear on how to do that would definitely be the case! Any help would be much appreciated.