Originally Posted by
syzygy
Yes, I believe you can make a 2D array of char pointers. However, I overlooked the fact that you were assigning the object inside the function. If you do make these pointers, then you suddenly have to worry about when the memory those pointers are pointing to get destroyed.
Basically, using references and pointers can save you a lot of memory and speed but it would be better to build some kind of memory/resource manager into the system if you do decide to do that. Otherwise, you will end up with crashes because things are referencing something that has suddenly been deleted and they haven't been notified about it.
So, for now, I would just stick with the copy, unless you feel like doing an overhaul (or maybe you already have something that manages things properly).
While it is true I am using the assignment op inside the function it only copies some basic data - ID size base damge/heal/restore/consumable(potions food etc)what type of item it is as well I do not share the BITMAP * or anything else within the character class reason being I can goto my primary game loop and pull from the resource manager any bitmap or sound file I need using a temp * to a PAS_Item all I need to know is the ID for the image so I do not worry about suddenly deleting something with the player and killing a pointer in the "real" world
[edit]
I may have forgotten to share the new code for that section....
Code:
PAS_Item& PAS_Item::operator=(const PAS_Item &rhs)
{
// Only do assignment if RHS is a different object from this.
if (this != &rhs)
{
ID = rhs.ID;
size = rhs.size;
min_damage = rhs.min_damage;
max_damage = rhs.max_damage;
min_heal = rhs.min_heal;
max_heal = rhs.max_heal;
min_restore = rhs.min_restore;
max_restore = rhs.max_restore;
armor = rhs.armor;
type = rhs.type;
Consumable = rhs.Consumable;
level = rhs.level;
for(int aq = 0;aq<5;aq++)
{
enhancements[aq] = rhs.enhancements[aq];
}
}
return *this;
}
UPDATE:
Strangely enough if I call the function in this manner it works would someone please explain what the big difference between what these two codes do?
Code:
PAS_Item DoNotCrash;
DoNotCrash = *resman->Get_Item(2);
player->AquireItem(DoNotCrash);
Code:
player->AquireItem(*resman->Get_Item(2));