#include #include #include #include #include "Example.h" using namespace std; unsigned int Example::globalId = 0; // The copy constructor for this class. // This default copy constructor does a shallow copy -- it // copies values field by field. Example::Example(const Example &other) { id = globalId++; strPtr = other.strPtr; cout << "Example copy constructor" << toString() << endl; } Example::Example(const char *strVal) { id = globalId++; strPtr = strdup(strVal); cout << "Example constructor" << toString() << endl; } Example::~Example() { cout << " Example destructor" << toString() << ")" << endl; free(strPtr); } string Example::toString() { ostringstream result; result << "[" << id << ": strPtr = 0x" << hex << (unsigned long int)strPtr << " -> '" << strPtr << "']"; return result.str(); }