hazarada wrote: |
---|
(also causing potential issues like triggering the new wat's deconstructor which could for example delete data pointed to in the class resulting in the assignment action destrying the data) |
I don't follow. Here's how I interpret lines 10 & 11:
First, an array of 5
::wats is created dynamically.
arrayofway now points to that memory. Then, the first element of
arrayofwat is assigned to a temporary
::wat instance. Before the assignment begins, the temporary instance calls the
wat::wat(int) constructor. Once fully constructed, the assignment is made. This assignment merely overwrites the data
arrayofwat0 contains. The assignment doesn't affect the allocated memory in any way (except for modifying the data within).
hazarada wrote: |
---|
So is there a way to allocate space for the array without using the new keyword while still it being in the right shape to be able to delete it with delete[] keyword? |
No, except for deleting constructors and operators (different context).
hazarada wrote: |
---|
because as far as i know delete[] is only guaranteed to work on things declared with new[]. |
That's true.
hazarada wrote: |
---|
Also allocating array space with new[] seems like a bad idea to begin with because just allocating space has to be simpler than allocating space and building data structures in it |
So what's the alternative? The stack? That's an even worse idea. The stack size is limited, but so is the heap. The heap, however, is far bigger than the stack. Usually a stack is 1 megabyte large, whereas modern systems have a heap size of 1GB+. Also, it sounds like you don't like the fact that objects are implicitly created within the allocated memory. Am I right?
Wazzak