C++ (Qt)#include <iostream>#include <cstdio>#include <vector>using namespace std; class Coord{private: int x, y;public: Coord(){x = 0; y = 0;} Coord(int _x, int _y){x = _x; y = _y;} Coord(const Coord &c){x = c.x;} ~Coord(){cout << "Delete Coord[" << x << ',' << y << "]" << endl;} Coord &operator=(const Coord &c); bool operator <(const Coord &c) const; friend ostream &operator <<(ostream& s, const Coord &c);}; Coord &Coord::operator =(const Coord &c){ if(this == &c)return *this; else { this->x = c.x; this->y = c.y; return *this; }} bool Coord::operator <(const Coord &c)const{ if(this->x < c.x)return true; else if(this->x == c.x) { if(this->y < c.y)return true; } return false;} ostream &operator <<(ostream& s, const Coord &c){ cout << "Coord[" << c.x << "," << c.y << "]" << endl; return s;} int main(){ vector<Coord> v; v.push_back(Coord()); v.push_back(Coord()); v.push_back(Coord()); cout << v[0]; cout << v[1]; cout << v[2]; getchar(); return 0;}
Delete Coord[0,0]Delete Coord[0,11665604]Delete Coord[0,0]Delete Coord[0,11665604]Delete Coord[0,825111086]Delete Coord[0,0]Coord[0,11669608]Coord[0,2037603443]Coord[0,1127952947]
Coord[0,11669608]Coord[0,2037603443]Coord[0,1127952947]
C++ (Qt)Coord(const Coord &c){x = c.x;}
C++ (Qt)Coord( int _x = 0, int _y = 0 ) { x = _x; y = _y; }
C++ (Qt)bool Coord::operator < ( const Coord & c ) const{ if (x < c.x) return true; if (x > c.x) return false; return y < c.y;}
C++ (Qt)Coord &Coord::operator =(const Coord &c){ if(this == &c)return *this; else { this->x = c.x; this->y = c.y; return *this; }}
C++ (Qt)Coord &Coord::operator =(const Coord &c){ if (this != &c) { x = c.x; y = c.y; } return *this;}