pdevries@watserv1.waterloo.edu (Peter DeVries) (05/02/90)
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