#include#include #include using namespace std; struct strtype { strtype(char *ptr); ~strtype(); void show(); private: char *p; int len; }; strtype::strtype(char *ptr) { len = strlen(ptr); p = (char *) malloc(len+1); if(!p){ cout << "error memory\n"; exit(1); } strcpy(p, ptr); } strtype::~strtype() { cout << "release p\n"; free(p); } void strtype::show() { cout << p << " - long: " << len; cout << "\n"; } int main() { strtype s1("this is a test."), s2("I like c++."); s1.show(); s2.show(); return 0; }

