#include <vcl> #include <iostream> #include <list> #pragma hdrstop using namespace std; class A { int x, y; A *p; public: A(int xx, int yy, A *p); A(int xx = -1, int yy = -1) : x(xx), y(yy), p(0) {} A& operator =(const A&); A operator +(const A&); bool operator ==(const A&); void show(); A get_p_value() const { return *p; } }; void A::show() { if (p != 0) cout << x << " " << y << " Right was: " << p->x << " " << p->y << endl; else cout << x << " " << y << " Right was: unknown" << endl; } A::A(int xx, int yy, A *pp) { x = xx; y = yy; p = pp; } A& A::operator =(const A& right) { if (this != &right) { p = right.p; x = right.x; y = right.y; } return *this; } A A::operator +(const A &right) { return A(x + right.x, y + right.y, const_cast<A*>(&right)); } bool A::operator ==(const A &right) { return x == right.x && y == right.y && p == right.p; } #pragma argsused // No warning if function args are not in use. // But there is no warning while compiling project. Why? int _tmain(int argc, _TCHAR* argv[]) { list<A> lst = list<A>(); A a1 = A(10, 10), a2(5, 7), a3; lst.push_back(a1); lst.push_back(a2); cout << "List before processing" << endl; for (list<A>::iterator it = lst.begin(); it != lst.end(); it++) it->show(); a3 = a1 + a2; lst.remove(a3.get_p_value()); cout << endl << "List after processing" << endl; for (list<A>::iterator it = lst.begin(); it != lst.end(); it++) it->show(); system("pause"); } |