Question: Now consider the Point class template from the Templates notes. Let's explore what constraints are associated with each of its member functions. For each of

Now consider the Point class template from the Templates notes. Let's explore what constraints are associated with each of its member functions. For each of the member functions listed below, what are the constraints on any template parameters associated with it? List the constraints separately (e.g., with a bulleted list); be as specific as possible about which constraints to include, but no single constraint requires you to write more than a few words.

  1. The constructor that takes three CoordinateType arguments.
  2. The copy constructor that initializes a Point of one type from a Point of a potentially different type.
  3. The assignment operator that assigns a Point of one type from a Point of a potentially different type.
  4. The x, y, and z member functions. (Note: Both overloads of all three of these will have the same constraints. Do you see why?)
  5. The distanceFrom member function.

#ifndef POINT_HPP #define POINT_HPP

#include

template class Point { public: Point( const CoordinateType& x, const CoordinateType& y, const CoordinateType& z);

template Point(const Point& other);

template Point& operator=(const Point& other);

CoordinateType& x() noexcept; const CoordinateType& x() const noexcept;

CoordinateType& y() noexcept; const CoordinateType& y() const noexcept;

CoordinateType& z() noexcept; const CoordinateType& z() const noexcept;

double distanceFrom(const Point& p) const;

private: CoordinateType x_; CoordinateType y_; CoordinateType z_; };

template Point::Point( const CoordinateType& x, const CoordinateType& y, const CoordinateType& z) : x_{x}, y_{y}, z_{z} { }

template template Point::Point(const Point& other) : x_{other.x()}, y_{other.y()}, z_{other.z()} { }

template template Point& Point::operator=(const Point& other) { x_ = other.x(); y_ = other.y(); z_ = other.z(); return *this; }

template CoordinateType& Point::x() noexcept { return x_; }

template const CoordinateType& Point::x() const noexcept { return x_; }

template CoordinateType& Point::y() noexcept { return y_; }

template const CoordinateType& Point::y() const noexcept { return y_; }

template CoordinateType& Point::z() noexcept { return z_; }

template const CoordinateType& Point::z() const noexcept { return z_; }

template double Point::distanceFrom(const Point& other) const { return std::sqrt( (x_ - other.x_) * (x_ - other.x_) + (y_ - other.y_) * (y_ - other.y_) + (z_ - other.z_) * (z_ - other.z_)); }

#endif // POINT_HPP

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!