Skip to content

Commit

Permalink
Merge pull request Mooophy#446 from Soyn/master
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
pezy committed May 3, 2016
2 parents b48b7c3 + 3f6de31 commit 32a8b81
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ch13/ex13_08.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Write the assignment operator for the HasPtr class from exercise 13.5 in 13.1.1 (p. 499).
// As with the copy constructor, your assignment operator should copy the object to which ps points.
//
// See ex13_05.h
// See ex13_05.h

#ifndef CP5_ex13_08_h
#define CP5_ex13_08_h
Expand All @@ -18,11 +18,13 @@ 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 &hp) {
std::string *new_ps = new std::string(*hp.ps);
delete ps;
ps = new_ps;
i = hp.i;
HasPtr& operator=(const HasPtr &rhs_hp) {
if(this != &rhs_hp){
std::string *temp_ps = new std::string(*rhs_hp.ps);
delete ps;
ps = temp_ps;
i = rhs_hp.i;
}
return *this;
}
private:
Expand Down

0 comments on commit 32a8b81

Please sign in to comment.