Path: utzoo!attcan!uunet!snorkelwacker!apple!rutgers!att!watmath!watserv1!pdevries From: pdevries@watserv1.waterloo.edu (Peter DeVries) Newsgroups: comp.lang.c++ Subject: access to private members Keywords: private, strings Message-ID: <1990May1.182725.11280@watserv1.waterloo.edu> Date: 1 May 90 18:27:25 GMT Distribution: comp Organization: University of Waterloo Lines: 44 On page 69 of the dewhurst / Stark book, they show the following method: String::operator char*() { char *p = new(char[strlen(str) + 1]; strcpy(p,str); return p; } They mention that this is good style to prevent user access to the private member 'str' if this routine simply returned its pointer. My problems are: 1) What about all our C routines that take a char* and want to modify this string. We would like to pass the String class to these routines and let the cast handle the conversion. 2) When do we free this memory...Is it not possible that temporary variables could be created from this cast....where do they get deleted? (ie. when passing to a function, or how about during an assignment...) 3) Can we not just as easily return the original char* from this routine and insure that our routines take the value in as const char *? Any comments would be appreciated.! Peter DeVries Mutual Life of Canada c/o pdevries@watserv1.waterloo.edu (519) 888-3523 (416) 972-0594 My opinions/comments are mine, and mine only, and have nothing to do with what Mutual Life of Canada thinks (now isn't that an understatement!) p. -- Peter DeVries Mutual Life of Canada c/o mgardi@watdcsu (519) 888-3523