// -*- coding: utf-8 -*- // Time-stamp: #ifndef TRACER_HPP #define TRACER_HPP // Class tracing calls to constructors and destructor class A { public: // Friend external output operator friend ostream& operator<<(ostream&, const A&); // Construtors A() : v(0) { cout << this << " : A()" << endl; } A(int n) : v(n) { cout << this << " : A(" << n << ")" << endl; } // Copy constructors A(const A& a) : v(a.v) { cout << this << " : A(const & " << &a << ")" << endl; } A(A& a) : v(a.v) { cout << this << " : A(& " << &a << ")" << endl; } // Move constructor A(A&& a) : v(a.v) { cout << this << " : A(&& " << &a << ")" << endl; } // Copy assignment operator A& operator=(const A& a) { v = a.v; cout << this << " : = (& " << &a << ")" << endl; return *this; } // Move assignment operator A& operator=(const A&& a) { v = a.v; cout << this << " : = (&& " << &a << ")" << endl; return *this; } // Conversion to an int // operator int() { return v; } // Destructor ~A() { cout << this << " : ~A()" << endl; } private: int v; // Value }; // External output operator ostream& operator<<(ostream& out, const A& a) { out << &a << " : " << a.v; return out; } #endif