Pointer question

This is a discussion on Pointer question within the C++ Programming forums, part of the General Programming Boards category; I am making an array of pointers to objects. I initialize the array by setting every pointer to NULL to ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    49

    Pointer question

    I am making an array of pointers to objects. I initialize the array by setting every pointer to NULL to indicate that the array element points to no object (and has always pointed to no object). Whenever an new object is declared, the value of one of the array elements is pointed at the new object.

    My problem is that whenever an object is removed from the array I would like to set the pointer at that element to a value such that I know a object was there, but has been deleted. I obviously cannot reset that pointer to NULL because NULL is my "flag" that the pointer at that element is, and always has, pointed to no objects. I need a unique "flaq" that indicates the pointer at that array element once pointed to an object but that it no longer does. Any suggestions as to how I can do this?

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    maybe you should create an object with a certain "indicator member" that is set to some arbitrary self indicating flag. Like 'count = -1', "name = "deleted". Then you can easily implement it by having all elements that get rid of their current objects, point to that indicator object. Then just test it by comparing the member with the arbitrary and unique flag.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    49
    Thx indigo0086, I just implemented something similar to that right now. I think that's the best flag I can use while dealing with array of pointers to objects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob silly pointer? question
    By darin722 in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2009, 06:58 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 09:54 AM
  4. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 10:59 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21