Is the following code correct?
#include <vector>
#include <memory>

using namespace std;

typedef vector<auto_ptr<int> > int_array;

void Test() {
  int_array a;

  for (int i = 0; i < 10; i++) {
    auto_ptr<int> p(new int(i));
    a.push_back(p);
  }
}
Explanation
No, because auto_ptr cannot be used as an element of an STL container.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes