0
How to store N objects pointer without STL
Hi Some weired requirement... No vector, no std::array , no stack , no queue Number of objects to be stored is also not fixed... How to store these objects I could think like this: T** ppT; ppT[0] = new T; By these , we could allocate individual pointer but is it only enough or do I have to allocate memory for double pointer? Any thoughts would be of great help. P.S. : T is class defined by us
3 Answers
+ 1
Yes you'll have to create pointers on the stack first
T * ppT[N];//N can be any number
Then you can use those stored pointers for dynamic memory allocation
ppT[0]=new T;ppT[2]=new T[50]; etc
+ 1
Hi Anthony Maina , it's true.. now a days compiler supports above without N being const.....
What to do if non constant N is not allowed
+ 1
In that case you'll have to just choose a number while writing the code
T*ppT[5];T*ppT[10]; etc