Point는 다음과 같이 정의한다.
Declare 2D Point Template Class
template < typename _tx >
class Point2
{
public:
typedef _tx valuetype;
union { struct {_tx x,y;} _tx _m[2]; }
public:
Point2() : x(0),y(0)
Point2(IN _tx _x, IN _tx _y) : x(_x),y(_y)
} ;Declare 3D Point Template Class
template < typename _tx > class Point3 { public: union { struct {_tx x,y,z;} _tx _m[3]; } public: Point3() : x(0),y(0),z(0) Point3(IN _tx _x, IN _tx _y,IN _tx _z) : x(_x),y(_y),z(_z) }
union을 사용한 이유는 Point를 사용할 때 x,y성분을 따로 쓰긴 하지만, 배열 형태로 사용할 수도 있다. 그래서 사용의 유연성을 확보하기 위하여 union을 기능을 사용한다.>
Posted by chungki


