Advertisement
Guest User

C++: issues with heap an functions, the gist

a guest
Mar 19th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. void manage_Rectangle_arr(string, Rectangle * *, short*);
  2.  
  3. int main()
  4. {
  5.     Rectangle * * arr;
  6.     short siArrayL=1;
  7.  
  8.     manage_Rectangle_arr("make array", arr, &siArrayL);
  9.     manage_Rectangle_arr("fill array", arr, &siArrayL); //Problem here
  10.     manage_Rectangle_arr("get areas", arr, &siArrayL); //Problem here
  11.     manage_Rectangle_arr("empty contents", arr, &siArrayL); //Problem here
  12.     manage_Rectangle_arr("delete array", arr, &siArrayL);
  13. }
  14.  
  15. void manage_Rectangle_arr(string strCommand, Rectangle * *arr, short *siArrayL)
  16. {
  17.     if(strCommand=="make array")
  18.     arr = new Rectangle * [ *siArrayL];
  19.  
  20.     if(strCommand=="fill array") //Problem here
  21.     for(short s=0; s< *siArrayL; ++s)
  22.     arr[s]= new Rectangle(1, 1);
  23.  
  24.     if(strCommand=="get areas") //Problem here
  25.     for(short s=0; s< *siArrayL; ++s)
  26.     cout << arr[s]->getArea();
  27.  
  28.     if(strCommand=="empty contents") //Problem here
  29.     for(short s=0; s< *siArrayL; ++s)
  30.     delete arr[s];
  31.  
  32.     if(strCommand=="delete array")
  33.     delete [] arr;
  34. }
  35.  
  36. //When I call manage_Rectangle_arr(string strCommand, Rectangle * *arr, short *siArrayL) with any of the following: "fill array", "get areas" and "empty contents" (obviously the last two are related to "fill array" in nature, since they need it to be executed first in order to function)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement