Best method to create dynamic array in Class?
|
|||
|
Rank: ? (5)
Member #: 28271 |
Hello,
I have a class which has a few structures too. One structure contains a large amount of arrays such as struct hi { int hello[200]; } the structure is then used in the class hi welcome[20]; However, on many occasions I do not need 20 instances of the welcome struct, therefore if I only need 10 I will be wasting 10*200 of system memory each time an instance of my class is created. What is the best method to ensure only the required amount of structures are established for each instance of the object? Many thanks |
||
|
|||
|
|||
|
Rank: ? (767)
Member #: 11085 |
Use the new operator.
Code:
Also, in the destructor, make sure you call delete [] welcome;
- relpats_eht
|
||
|
Please login or register to post a reply.