I have 3 short classes below. My question is also in the code below.
template< typename T >
class XY
{
public:
XY() = default;
XY(T x, T y) { vec2 = { x,y }; }
virtual ~XY() = default;
auto X() const -> T { return vec2[0]; }
auto Y() const -> T { return vec2[1]; }
private:
std::array<T, 2> vec2;
};
template< typename T >
class xy
{
public:
xy() = default;
xy(T xx, T yy) : x(xx), y(yy) {}
virtual ~xy() = default;
T x, y;
};
template<typename T>
class coordinates {
public:
T _pp;
void printcoordinates() {
// how can I refer to _pp.x or _pp.X() when it T can be either XY or xy
_pp.x or _pp.X();
_pp.y or _pp.Y();
}
};
}
I have 3 template classes, XY
, xy
, and coordinates
. Please see the code snippets above, in coordinates
, how can refer to XY.X() and xy.x?
New contributor
taitai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.