In the previous topic memory for array of objects was static as the memory was allocated at compile time. To allocate memory dynamically or at run time, we use an array of pointers which can be created as follows: ClassName *array-name; Memory allocated for an array of pointers is far less than memory allocated for an array of objects. We can create an object at run time using the new operator as follows: array-name = new ClassName; After dynamically allocating memory for an object we access the members using the -> operator as follows: array-name->member; Below example
The post How to Dynamically allocate objects in arrays using C++ appeared first on Coding Security.
How to Dynamically allocate objects in arrays using C++
read more
Tidak ada komentar:
Posting Komentar