13.22
#include <string>
class HasPtr {
public:
HasPtr(const std::string &s = std::string()) : ps(new std::string(s)), i(0) { }
HasPtr(const HasPtr& hp) : ps(new std::string(*hp.ps)), i(hp.i) { }
HasPtr& operator=(const HasPtr& rhs){
if(this=&rhs)
return this;
delete ps;
ps=new string (*rhs.ps);
i=rhs.i;
return *this;
}
~HasPtr(){
delete ps;
}
private:
std::string *ps;
int i;
};