Good morning. I am having trouble understanding the logic behind deep and shallow copying with objects in C++ in a shared project, so I have created the following example.
int main() {
ObjectAType* objecta = ObjectAType::New();
ObjectBType* objectb = ObjectBType::New();
// some operation to populate data members of object a
objecta->Operation();
// assume I have accessors to return datamembers of object a
// I wish to make a deep copy of SOME of those data members into object b
objectb->AlignWithA(objecta);
objecta->Delete();
objectb->Delete();
return 0;
}
Now given the object b class function as follows:
public:
void ObjectBType::AlignWithA(ObjectAType* objecta) {
this->ObjectBDataMember = objecta->DataAccessor();
}
protected:
int ObjectBDataMember;
And the data accessor is just something like this within the class def,
public:
int ObjectAType::DataAccessor() {
return this->ObjectADataMember;
}
protected:
int ObjectADataMember;
I have a few resulting questions.
1) Since in object b, the data member is declared as
int ObjectBDataMember;
and not as
int *ObjectBDataMember;
why is the data member accessed as
this->ObjectBDataMember
and not as
this.ObjectBDataMember
?
2) Is this a deep or shallow copy?
I apologize if I have left out important bits. I'm not much of a programmer so things like this easily confuse me. The literature has just confused me further. Thank you for your time.