Yep, lots of these threads seem to just hang..
I want to define lots of them but dont want to have to create as many
dummy object/pointers as there are array objects
You will have to use a loop of soughts anyway, so why not just assign/create to each array element in turn. Using the loops increment to index the array elements.
1 How can I just use one dummy object/pointer to define n array objects?
Define the pointer globally, do all the work in a loop.
Or define the array globally and assign directly to each element in a loop, by passing the need for the pointer.
Or define the pointer in a function and the array globally. Either way, you will need to do it all in a loop of some kind. And if the array isn't global, you wont be able to reference the objects after the called function returns.
2 How can I delete either the dummy pointer ...
If you put the pointer in a function, it will either be overwritten on the next function call (stack based), or if globally declared, it will exist for the programs life. Thats the point to global variables.
Besides, it's really just a type of integer anyway. So it doesn't take up much space.
If you call delete on the pointer it will free the objects memory space. It wont get rid of the pointer. And the relevant array element will be pointing to a freed memory area.
Besides, the memory area wont be zeroed or anything anyway, justs its' memory space will go on the free list. What ever is there is still accesable via its' pointer, well, depending that is.
Try an exp. Create an object ... delete it by calling delete on the pointer that's assigned its' address. Then dereference the object. If the compiler doesn't impose some locks or something it should succeed. But as the memory is also on the free list, depending on what the program is doing the memory could be reused. And the dereference could be pointing within some other allocation. And depending on what kind of object it is. Potentially Exceptional Behaviour May Occur
Works with simple things like integer objects. Create and assign to them. delete them, then cout them (grin). If your program wants/needs a paranoid level of security, you would need to get the objects size, then treat it as a byte array. Passing it through a loop zeroing each byte in turn. Then calling delete on its' pointer. Sounds like the kind of thing that should be a lib function in itself really, if it isn't already hidden in there somewhere.
dummy object deletion, how do you deallocate dummy variables in the global namespace
When the program ends and the process space is freed.
You can make it specific to the unit file by declaring it static iirc.
You don't. Thats the whole point to a global type. Primitives like numbers, pointers, don't take up a lot of space and are usually things that are required for program life. If you declare the primitive in a function, it will be stack based and so will disappear on the functions return. The objects themselves will be on the heap though.
If you put both the pointer and array declarations in a function, you will end up with a global mem allocation that hasn't got a means of being referenced, on the functions return. So you would have to do all the work within the function, including the deletions. A bit messy really.
3 re the dummy object deletion, how do you deallocate dummy
variables in the global namespace
eg int a; //outside any variable.
Again, you don't need to. The class declaration wont allocate any space. Only the call to 'new' will involve a memory allocation. So any variables wrapped in the object will be freed (but still there) on the call to delete.
Once you have assigned the pointers value to the array element, then you have the objects address as the value of the array element. Creating a new object and assigning to the same pointer will just give it the new address. The pointer functions like an integer in that respect, but typed differently. You don't need to clean or do anything like that to the pointer in between object creations. Its value will just get overwritten with a new address on each iteration of the loop. At the end of the loop it will point to the same address as the last element in the array.
You could get into the trap of trying to delete an object twice, in that the pointer and the current array element will both point to the same place with each pass through the loop.
The use of the pointer is good because it helps make clear what your doing. It can still be understood this time next week. But i'd tend to just use a 'for' loops increment to index the array, and create each object assigning the address directly. It may be clear too that way, as less steps would be involved.
Hope i haven't miss-interpreted the question to much here (grin)