2010-05-27 2 views

Répondre

6

Ecrire

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; 

ou quelque chose comme ça. C'est très simple.

+0

Merci pour cela. – boom

11

n °

Ces langues ne comprennent généralement pas d'API et de types spécifiques à l'application.

Microsoft Win32 API comprend un type appelé RECT, et il y en a probablement d'innombrables autres une fois que vous commencez à regarder l'API externe: s.

+0

D'autres cadres fournissent également des types pour un rectangle. Ils peuvent ou non être équivalents à Microsoft. –

Questions connexes