c++ - deleting an array that stores pointers to some objects -


I am accumulating elements of vec_A elements in array A * a_ptrs [3] . Assume that the size of vec_A will not be changed. Therefore, a_ptrs [i] will point to the correct element.

My question is this:

Suppose A * an_ptrs [3] is a class B . Since it is not using the 'new', I am guessing that I do not need to remove it in a disaster. Am i right

  Class A {Public: int getNumber (); A (int.); ~ A () {}; Private: integer number; }; A: A (int val) {num = val; }; Int a :: getNumber () {Return to num; }; Int main () {int i = 0; Int num; Std :: vector & lt; A & gt; Vec_A; For (i = 0; i <10; i ++) {vec_A.push_back (A (I)); } A * a_ptrs [3]; A_ptrs [0] = & amp; Vec_A [0]; A_ptrs [1] = & amp; Vec_A [3]; A_ptrs [2] = & amp; Vec_A [5]; (I = 0; i & lt; 3; i ++) {std :: cout & lt; & Lt; "\ N: an_ptrs [i] .getNumber () =" & lt; & Lt; A_ptrs [i] - & gt; GetNumber (); } Std :: cout & lt; & Lt; "Press return to continue \ N ..."; Std :: cin.get (); Return 0; }  

Yes, that's right. You do not need to use the removal only The issue is that if the vector is resized then by calling Push_back etc. - but you called it in your post.


Comments