2010-05-27 52 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