-
newb question
Ok. I ll note post all the code not to make things complicated. I have two classes:
Code:
class Character
{
...
Weapon rightHand;
...
};
class Weapon : public Item
{
...
}
I want to do this:
Code:
Character newb;
Weapon w;
newb.rightHand = w;
If I undestand correctly newb.rightHand will have a copy of w. Thus you will have double the memory for the a Weapon object. Is that bad programming? Would it make more sense having a pointer that will point to the object Weapon instead of copying the whole object?
-
I suppose it depends on what is going on within the Weapon function. Generally speaking this seems fine. If you are worried about the level of overhead in copying over a weapon then why not just use a (smart) pointer? Can I assume that rightHand is a public member of Character?
-
I'd suggest using a Factory.
-
You could probably also do:
Code:
Character newb;
newb.righthand = Weapon();