写
template<class T>
struct podrect
{
T left;
T top;
T right;
T bottom;
};
template<class T>
struct rect
{
rect() : left(), top(), right(), bottom() {}
rect(T left, T top, T right, T bottom) :
left(left), top(top), right(right), bottom(bottom) {}
template<class Point>
rect(Point p, T width, T height) :
left(p.x), right(p.y), right(p.x + width), bottom(p.y + height) {}
T left;
T top;
T right;
T bottom;
};
typedef rect<int> intrect;
typedef rect<float> floatrect;
Run Code Online (Sandbox Code Playgroud)
或类似的东西.这很简单.