Properly handle self-assignment

This commit is contained in:
Dmitry Marakasov 2014-02-11 05:42:51 +04:00
parent 1e4e1cb560
commit 66f4d5b57a
2 changed files with 12 additions and 4 deletions

View File

@ -43,7 +43,9 @@ Point Point::Null() {
}
Point::Point(const Point& other) {
if (other.point_.get()) {
if (!other.point_) {
point_.reset(nullptr);
} else if (point_ != other.point_) {
point_.reset(new SDL_Point);
point_->x = other.point_->x;
point_->y = other.point_->y;
@ -53,7 +55,9 @@ Point::Point(const Point& other) {
Point::Point(Point&&) noexcept = default;
Point& Point::operator=(const Point& other) {
if (other.point_.get()) {
if (!other.point_) {
point_.reset(nullptr);
} else if (point_ != other.point_) {
point_.reset(new SDL_Point);
point_->x = other.point_->x;
point_->y = other.point_->y;

View File

@ -45,7 +45,9 @@ Rect Rect::Null() {
}
Rect::Rect(const Rect& other) {
if (other.rect_.get()) {
if (!other.rect_) {
rect_.reset(nullptr);
} else if (rect_ != other.rect_) {
rect_.reset(new SDL_Rect);
rect_->x = other.rect_->x;
rect_->y = other.rect_->y;
@ -57,7 +59,9 @@ Rect::Rect(const Rect& other) {
Rect::Rect(Rect&&) noexcept = default;
Rect& Rect::operator=(const Rect& other) {
if (other.rect_.get()) {
if (!other.rect_) {
rect_.reset(nullptr);
} else if (rect_ != other.rect_) {
rect_.reset(new SDL_Rect);
rect_->x = other.rect_->x;
rect_->y = other.rect_->y;