簡體   English   中英

用c或c ++語言表示

[英]rect in c or c++ language

在C語言中是否有一個名為rect的類型或者在C ++語言中有一個類Rect。

沒有。

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

微軟的Win32 API包含一個名為RECT的類型,一旦你開始關注外部API,可能還有無數其他的。

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;

或類似的東西。 這很簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM