#include #include using namespace std; struct noisy_string { string buf; noisy_string (const char* str) : buf (str) { cout << "noisy_string::ctor: " << *this << endl; } noisy_string (const noisy_string& d) : buf (d.buf) { cout << "noisy_string::copy ctor: " << *this << endl; } ~noisy_string () { cout << "noisy_string::dtor: " << *this << endl; } noisy_string& operator= (const noisy_string& d) { if (this != &d) buf = d.buf; cout << "noisy_string::op=: " << *this << endl; return *this; } friend ostream& operator<< (ostream& os, const noisy_string& d) { os << (void*) &d << ": " << d.buf; return os; } }; noisy_string answer () { noisy_string d ("forty-two"); return d; } int main (int argc, char* argv[]) { noisy_string i = answer (); }