Thread: not a pointer issue

  1. #46
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Quote Originally Posted by syzygy View Post
    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

    I may have forgotten to share the new code for that section....
    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;

    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?

    PAS_Item DoNotCrash;
    DoNotCrash = *resman->Get_Item(2);
    Last edited by ~Kyo~; 04-21-2010 at 10:51 PM. Reason: UPDATE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with pointer issue
    By ph5 in forum C Programming
    Replies: 4
    Last Post: 11-17-2009, 04:19 PM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM