I want to draw rectangles in a window in C. I found the following C++ code I want to convert its classes to C struct to use it in my C project. I want to convert the following C++ class to C struct:
class Rect{
public:
int x1;
int y1;
int x2;
int y2;
Rect * next;
Rect(){
x1 = y1 = x2 = y2 = 0;
next = NULL;
}
void draw(Display* d, Window w, GC gc){
if((x1<x2) && (y1<y2)){
XDrawRectangle(d, w, gc, x1, y1, x2-x1, y2-y1);
}
if((x1<x2) && (y1>y2)){
XDrawRectangle(d, w, gc, x1, y2, x2-x1, y1-y2);
}
if((x1>x2) && (y1>y2)){
XDrawRectangle(d, w, gc, x2, y2, x1-x2, y1-y2);
}
if((x1>x2) && (y1<y2)){
XDrawRectangle(d, w, gc, x2, y1, x1-x2, y2-y1);
}
}
};
I saw that it's possible to convert some C++ classes to C structs here and here but the above class contains constructor. How can I convert a class which contains constructors into C struct and use it safely?