1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <iostream> using namespace std;
struct Box2D { Box2D() : x0(), x1(), y0(), y1() { } Box2D(int x0_, int x1_, int y0_, int y1_) : x0(x0_), x1(x1_), y0(y0_), y1(y1_) { } Box2D shift(int deltaX, int deltaY) const { return Box2D(x0+deltaX, x1+deltaX, y0+deltaY, y1+deltaY); }
bool operator==(Box2D const& rhs) const { return x0 == rhs.x0 && y0 == rhs.y0 && x1 == rhs.x1 && y1 == rhs.y1; }
int x0, x1, y0, y1; };
int main() { Box2D box = {1,10,2,9}; cout << "box: " << box.x0 << " " << box.x1 << endl; Box2D box1,box2; cout << "box1: " << box1.x0 << " " << box1.x1 << endl; box2 = box.shift(1,2); cout << "box2: " << box2.x0 << " " << box2.x1 << endl; box1 = box2; cout << "box1: " << box1.x0 << " " << box1.x1 << endl;
if (box1 == box2) { cout << "There are equal!" << endl; }
return 0; }
|