From 91c12014ff9698b2c5c2745b09c8aa92ddb2b515 Mon Sep 17 00:00:00 2001
From: Aaron Feldman
Date: Sun, 20 Mar 2016 21:00:16 -0700
Subject: [PATCH] Our copy constructor is unnecessary
Our assignment operator is also unnecessary. They are both identical to
the defaults. Reword to make that clear.
Closes https://github.com/caltechcs2/maze/issues/3
---
assignment3.html | 6 ++----
maze/src/common.hpp | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/assignment3.html b/assignment3.html
index 2fe0ea6..05f5989 100644
--- a/assignment3.html
+++ b/assignment3.html
@@ -303,10 +303,8 @@ Part 1: Maze solving
You have been provided a Coordinate class
in maze/src/common.hpp, a simple wrapper around
-two integers representing zero-based maze coordinates. We have given you
-two constructors and an assignment operator for this class to make it
-easier to pass-by-value and return-by-value. It is worth your time to
-study the provided code before you start!
+two integers representing zero-based maze coordinates. When you work with this
+class, think of what it means to pass-by-value and return-by-value.
Part 1.1: CoordinateStack class
diff --git a/maze/src/common.hpp b/maze/src/common.hpp
index bd220e3..9dbf786 100644
--- a/maze/src/common.hpp
+++ b/maze/src/common.hpp
@@ -60,16 +60,38 @@ class Coordinate
int x;
int y;
+ // Constructor
Coordinate(int i = 0, int j = 0)
{
x = i; y = j;
}
+ // This is a "copy constructor." It is actually identical to the default
+ // copy constructor that C++ provides; we only include it for teaching
+ // purposes.
+ // Example:
+ // Coordinate a(1, 2);
+ // Coordinate b = a; // Copy constructor gets called to construct `b`
+ // // The argument to the constructor is a const
+ // // reference to `a`
+ // The copy constructor also gets called when you pass a Coordinate as an
+ // argument to a function, and when your return a Coordinate from a
+ // function.
+ // See if you want to learn
+ // more about copy constructors and assignment operators.
Coordinate(const Coordinate &other)
{
x = other.x; y = other.y;
}
+ // This is an "assignment operator." It is actually identical to the default
+ // assignment operator that C++ provides; we only include it for teaching
+ // purposes.
+ // Example:
+ // Coordinate a(1, 2);
+ // Coordinate b(2, 3);
+ // b = a; // Assignment operator gets called with a const reference
+ // // to `a` as the argument. Assigns to b.
Coordinate& operator= (const Coordinate &source)
{
x = source.x; y = source.y;