I want to make a class that creates an instance of an arbitrary struct and then has methods to write and load these structs from a file system. I currently do this with a macro that takes the name of the instance of the struct and saves and loads it. I wanted to instead create a class object that would wrap all of these together, but I don't know how to pass and use an arbitrary struct to the constructor.
I am limited to C++11. The code would work something like this
struct typeA{
int age;
int weight;
};
struct typeB{
char name[10];
int height;
};
class StructControl{
public:
void target;
StructControl(void ITEM){
ITEM target;
}
void S(void * addr,uint32_t size){
//code for saving
}
void L(void * addr, unint32_t size){
//code for loading
}
void Save(){
S(&target,sizeof(target));
}
void Load(){
L(&target,sizeof(target));
}
};
void main(){
StructControl myA(typeA);
myA.target.age=45;
myA.Save();
StructControl myB(typeB);
myB.height=110;
myB.Save();
}