mardi 7 avril 2015

Proper way to copy a const* instance of MyGreatClass

Vote count:


So I have a class like so...

struct MyGreatClass
int someInt;
float someFloat;

which is inside another class...

struct MyEvenBetterClass
const MyGreatClass* great;//do not, can not, must not change!

MyEvenBetterClass(MyGreatClass* grr);//constructor...


which is constructed like this:

MyEvenBetterClass::MyEvenBetterClass(MyGreatClass* grr)
great = grr;

using this code:

MyGreatClass instanceOfGreatClass;
instanceOfGreatClass.someInt = 8;
instanceOfGreatClass.someFloat = 4.5f;

MyEvenBetterClass instanceOfMyEvenBetterClass(&instanceOfGreatClass);

Right. Now say I want to copy the properties of the const* instance of MyGreatClass inside the I need to do something like this:

MyGreatClass::MyGreatClass(const* MyGreatClass mGC)//another constructor
this->someInt = mGC->someInt;
this->someFloat = mGC->someFloat;

and then create an instance like so: MyGreatClass changableGreatClass(instanceOfMyEvenBetterClass.great);

Or is there a better way...?

asked 16 secs ago



Proper way to copy a const* instance of MyGreatClass

Aucun commentaire:

Enregistrer un commentaire