trl@cbrma.UUCP (Tom Lanning) (03/05/86)
I have a class, "string", that can be converted to "char*". I want the converted object to be "readonly", i.e. "const". I have been using "operator char* ()", but would like to know if there is a way to get "const char*". I do not want to use intermediate types since I want to use "string" and "const char*" together without explict type casting. Any help would be appreciated, thanks. -- Tom Lanning AT&T Bell Laboratories Columbus OH 43213 614-860-4153
aglew@ccvaxa.UUCP (03/07/86)
>/* Written 6:12 pm Mar 4, 1986 by trl@cbrma.UUCP in ccvaxa:net.lang.c++ */ >/* ---------- "type casting and const" ---------- */ > > I have a class, "string", that can be converted to "char*". I >want the converted object to be "readonly", i.e. "const". I have been >using "operator char* ()", but would like to know if there is a way >to get "const char*". I do not want to use intermediate types since >I want to use "string" and "const char*" together without explict type >casting. Any help would be appreciated, thanks. >-- > > Tom Lanning AT&T Bell Laboratories Columbus OH 43213 614-860-4153 >/* End of text from ccvaxa:net.lang.c++ */ This raises another interesting point: is it possible to require read-only-ness as part of the description of the type to which a pointer refers? Verbosely "pointer to const int", *(const int), so that int i; const int j = 666; int *pv; const int *pc; // or something like pv = &i; *pv = 1; //succeeds pv = &j; *pv = 2; // should fail, perhaps at compile time? pc = &i; *pc = 3; // should fail AT COMPILE TIME pc = &j; *pc = 4; // ditto. Or is the only way to define a new class, overloading assignment, etc?