The situation is like this:
I know what the max number of the dimension of my data structure will be. But in the case, that the actual space needed is less than max, I would like to delete the unused space.
So, I was thinking something like this, but it won't work
Of course, I made this code only to test this idea.Code:#include <iostream> using namespace std; class foo{ public: foo(){x=0;y=0;z=0;d=0;} double x; double y; double z; double d; }; int main() { foo* p; p = new foo[8]; for(int i = 0 ; i < 8 ; i++) cout << i << " " << p[i].x << " " << p[i].y << " " << p[i].z << " " << p[i].d << endl; foo* pp = &p[5]; delete [] pp; return 0; }
Any approaches/ new ideas are welcome.