![]() |
|
#1
|
|||
|
|||
need a quickie, initializers with dynamic allocation...If I have this class...
CPP / C++ / C Code:
Can a do a dymanic allocation with the initializers... CPP / C++ / C Code:
Thank you! Regards. |
|||
|
#2
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation...Quote:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation...thanks OCICAT for the quick response.
That's what I believed to be true. I was hoping for a different answer, but I read that else where and just wanted to be sure. I know there will only be two instances of the Object at runtime so I'm doing an array of two, but I kind of wanted to control the destruction of the instance. Thank you. Regards. |
|
#4
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation...Quote:
|
|
#5
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation......okay?, how do I destory just one of the two instances? using this example.
CPP / C++ / C Code:
Thank you. Regards. |
|
#6
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation...Quote:
So if you want to call different constructors for the various elements within an array, you can get around the above restriction by creating an array of class instance pointers. Since you ask how to uniquely destroy objects at will (which is unrelated to array initialization...), consider the following example which mixes both concepts of unique constructor calls for array elements & absolute control over object destruction: CPP / C++ / C Code:
Since the language standard does not define what the behaviour should be if the destructor is called on the same address multiple times (In other words, what will happen if I call the destructor multiple times on the same address?), the behaviour seen with one vendor's compiler is not guaranteed with another. The safe solution is to set the address to 0 after destruction as the behaviour of deleting an address value of 0 is well defined -- nothing. |
|
#7
|
|||
|
|||
Re: need a quickie, initializers with dynamic allocation...That's it, that will work prefectly with what I have.
I made the changes and now its controllable! Thank you OCICAT. Regards. |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| custom array class: operator[] not working for new dynamic allocation | transfrank | C++ Forum | 3 | 06-Sep-2007 16:34 |
| Dynamic 2D Array pointers, Allocation, and input | Assiral | C Programming Language | 3 | 27-Oct-2006 14:44 |
| Help with OOP classes and Dynamic Allocation | noob2c++ | C++ Forum | 3 | 18-Sep-2006 18:41 |
| Dynamic memory allocation - Dangling pointers revisited | karthikeyansen | C++ Forum | 13 | 27-Jul-2005 16:30 |
| 3D array dynamic memory allocation | cjwatchdog | C Programming Language | 3 | 20-Feb-2004 16:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The