Let's explore what constraints are associated with each of its member functions. For each of the member
Question:
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.
- The constructor that takes three CoordinateType arguments.
- The copy constructor initializes a Point of one type from a Point of a potentially different type.
- The assignment operator assigns a Point of one type from a Point of a potentially different type.
- The x, y, and z member functions. (Note: Both overloads of all three of these will have the same constraints. Do you see why?)
- 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
(language C++P)