0

I want to create a structure of array dynamically but i dont know the exact size so it will be added whenever i want...

Consider the following example..

 Struct abc
 {
    double **ptrPoints;
    int size;    
  };

i am defining pointer variable

abc* obj;

i dont know the exact size will be so i can not defile like

obj = new abc[size];

the elements will be added whenever condition satisfied.. i want it like vector but i dont want to use it ....

Please suggest me any way to write the functionality like this... Thank u

Jitendra
  • 55
  • 1
  • 3

2 Answers2

2

Look up vector. Does all the leg work for you.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
0

Wonder why you do not want to use vector. But you may initially declare array of sufficient size. Then maintain a counter of the elements being used up. If it has no space then use realloc.

Seems the only solution except vectors.

See THIS for realloc

Saksham
  • 9,037
  • 7
  • 45
  • 73
  • 7
    Please do not use `malloc/realloc/..` for C++. C++ uses new and perhaps has different house keeping rules. – Ed Heal Aug 09 '13 at 06:00
  • @EdHeal can I get an idea how to replace `realloc` with `new[]` and `delete[]` – Saksham Aug 09 '13 at 06:03
  • 1
    @Saksham, There's placement new for that purpose. Of course using either is not usually in your best interest. – chris Aug 09 '13 at 06:06