Let's say I have this code (minimal example):
class ImportantClass(){
public:
ImportantStuff(){};
~ImportantStuff(){};
someVector importantStuff1;
someStruct importantStuff2;
someType importantStuff3;
someClass importantStuff4;
void fillImportantStuff(){
//...do stuff
}
};
class ClassA{
public:
ClassA(){};
~ClassA(){};
//...functions that need access to "importantStuff1,2,3,4"
};
int main(){
ImportantClass importantObject;
importantObject.fillImportantStuff();
ClassA object1;
ClassA object2;
ClassA object3;
ClassA object4;
return 0;
}
And in words:
I have one class (ImportantClass) of which I will probably just have one object holding some different variables. I then have another class (ClassA) of which I will have many objects. Each of these object should have access to the variables in the object "importantObject".
I tried this:
class ClassA{
private:
ImportantClass* _importantClassObject;
public:
ClassA(ImportantClass* x){_importantClassObject = x;};
~ClassA(){};
//...functions that need access to "_importantClassObject"
};
But when I create an object of ClassA:
ImportantClass importantObject;
importantObject.fillImportantStuff();
ClassA object1(&importantObject);
I get a argument list mismatch error.
I guess my question would come down to:
What is common practice to share an object holding a lot of data with multiple objects of a different class?