This topic is now archived and is closed to further replies.

Ronin Magus

Deleting pointers

Recommended Posts

Ronin Magus    142
Do I have to delete a pointer that does not point to a new item on the stack? I need to brush up on my pointers Well I've got a vector and a pointer is declared to point to an item in the vector, but no new data is being allocated for the pointer. I think I don't have to delete it but I'm just making sure by asking. Just my code to look at:
struct SG_Window
SG_WindowRef ref;
bool (*fpEventHandler) (SG_WindowRef, SG_Message, Uint32, Uint32);


SG_Window * SG_GetWindowByRef(SG_WindowRef ref)
// returns a pointer to a window by searching for its reference

  if(ref != 0)
    for(int i = 0; i < SG_WindowList.size(); i++)
       if(SG_WindowList[i].ref == ref)
         return &SG_WindowList[i];

  return NULL;

bool SG_HandleMessage(SG_WindowRef ref, SG_Message msg, Uint32 data, Uint32 extra)
  SG_Window * target;

  if (ref)
    target = SG_GetWindowByRef(ref);

    if(target != NULL && target->fpEventHandler(ref, msg, data, extra))
      return true;

  [handle system messages, return true if handled ...]

  cout << "Unhandled message: " << msg << endl;
  cout << "Sent to window: " << ref << endl;

  return false;

There's a lot more but I just pasted what was important. Basically I'm wondering if I need to delete SG_Window * target in function SG_HandleMessage. - Find any acronym you need! [edited by - Ronin Magus on October 22, 2002 7:39:55 PM]

Share this post

Link to post
Share on other sites