It is said that we should always use std::unique_ptr
instead of std::auto_ptr
and it is said that we were not able to store a auto_ptr
in a container But consider this example:
int main(int argc, char* argv[]){
std::vector< std::auto_ptr<int> > v;
std::auto_ptr<int> u(new int(5));
v.push_back(u);
v.push_back(std::auto_ptr<int>(new int(10)));
typedef std::vector< std::auto_ptr<int> >::iterator v_ap_it;
for(v_ap_it beg = v.begin(), e = v.end(); beg != e; ++beg)
std::cout << **beg << " ";
std::cout << std::endl;
return 0;
}
The program runs fine. I've tested it on vC++ 6.0 and it works fine but doesn't run on C++11 and C++14 ! So how could it be not possible to store it in a container? * does this mean VC++ 6.0 is erroneous? I think so because it a buggy IDE.