tags:

views:

134

answers:

2

Hi,

Is there a type called rect in C or class Rect in C++ language.

+10  A: 

No.

These languages generally don't include application-specific APIs and types.

Microsoft's Win32 API includes a type called RECT, and there are probably countless others once you start looking at external API:s.

unwind
Other frameworks also provide types for a rectangle. They may or may not be equivalent to Microsoft's.
Thomas Matthews
+2  A: 

Write

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;

or something like this. It's very simple.

Alexey Malistov
@Alexey Thanx for this.
iSight