#pragma warning(disable : 4996) #include #include using namespace std; class str { public : char* p; int size; str(int sz) { p=new char[size=sz] ; cout << " Constructor &p " << &p << " p = " ; cout << p << endl; } ~str() { cout << " Destructor &p " << &p << " p = " ; cout << p << endl; delete[] p; } str(const str&); }; str::str(const str& c) { cout << " copy constructor \n"; p=new char[size=c.size]; strcpy(p,c.p); } void bar(str fred) { cout << " Address of fred " << &fred << endl; cout << " fred.p " << fred.p << endl; cout << " bar going out of scope - " ; cout << " a destructor will be called " << endl; } void foo() { str s1(10); strcpy(s1.p,"abcdefghi"); cout << " Address of s1 " << &s1 << endl; cout << " s1.p " << s1.p << endl; bar(s1); cout << " Address of s1 " << &s1 << endl; cout << " s1.p " << s1.p << endl; return; } int main() { int i; cout << " Program starts \n"; foo(); cout << " Back in main - "; cout << " Type an integer to continue \n"; cin >> i; return(0); }