用c或c ++语言表示

boo*_*oom 2 c++

在C语言中是否有一个名为rect的类型或者在C++语言中有一个类Rect.

unw*_*ind 12

没有.

这些语言通常不包括特定于应用程序的API和类型.

微软的Win32 API包含一个名为RECT的类型,一旦你开始关注外部API,可能还有无数其他的.


Ale*_*tov 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;
Run Code Online (Sandbox Code Playgroud)

或类似的东西.这很简单.