// File: des10a.C // // The dangers of destructors, part 10 version a // // Using reference parameters and reference return values solves // our problems on (most ?) compilers. #include #include #include "string.h" #include "record2.h" void foo(Record& T, Record& P) { Record *Rptr ; Rptr = new Record("R") ; printf("\nIdentify T: ") ; T.id() ; printf("\nIdentify *Rptr: ") ; Rptr->id() ; P = *Rptr ; Rptr->str = NULL ; delete Rptr ; } main() { Record S("S") ; Record P ; char *str1, *str2 ; printf("Identify S: ") ; S.id() ; printf("\nDo Assignment\n") ; foo(S, P) ; printf("Finished Assignment\n\n") ; str1 = strdup("Hello") ; printf ("str1=(%p,\"%s\")\n", str1, str1) ; str2 = strdup("World") ; printf ("str2=(%p,\"%s\")\n", str2, str2) ; printf("Identify S: ") ; S.id() ; printf("Identify P: ") ; P.id() ; printf("\n\nEnd of main()\n\n") ; }