Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions assignment3.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,8 @@ <h3>Part 1: Maze solving</h3>

<p>You have been provided a <span class="code">Coordinate</span> class
in <span class="code">maze/src/common.hpp</span>, 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!</p>
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.</p>

<h4>Part 1.1: CoordinateStack class</h4>

Expand Down
22 changes: 22 additions & 0 deletions maze/src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include this exposition? Or just remove the unnecessary copy constructor and assignment operator?

// 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 <http://www.cplusplus.com/articles/y8hv0pDG/> 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;
Expand Down