auto_ptr
auto_ptr have an unusual characteristic: copying them(via copy constructor or copy assignment)sets them to null.
why the program run correctly:
#include <stdAfx.h>
#include <iostream>
#include <memory>
using namespace std;
class A
{
public:
A(int a):m_iData(a){};
void print(){cout<<this->m_iData<<endl;}
private:
int m_iData;
};
void smart()
{
auto_ptr<A> m_pSmartA(new A(2));
//m_pSmartA->print();
auto_ptr<A> m_pSmartA1(m_pSmartA);
m_pSmartA1->print();
m_pSmartA->print();
};
void main()
{
smart();
}
the result:
2
2
i was puzzled how the result got.
can u tell me why? thank u first.