2010-05-27 54 views

回答

6

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; 

或這樣的事情。這很簡單。

+0

Thanx爲此。 – boom 2010-05-27 13:24:01

11

編號

這些語言通常不包括特定於應用程序的API和類型。

微軟的Win32 API包含一個名爲RECT的類型,並且在開始查看外部API時可能會有無數其他人。

+0

其他框架也提供矩形的類型。他們可能會或可能不會等同於微軟的。 – 2010-05-27 17:42:05