Thread View: net.lang.c++
2 messages
2 total messages
Started by Tom Lanning
Wed, 05 Mar 1986 00:12
type casting and const
Author: Tom Lanning
Date: Wed, 05 Mar 1986 00:12
Date: Wed, 05 Mar 1986 00:12
10 lines
1022 bytes
1022 bytes
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
Re: type casting and const
Author: aglew
Date: Fri, 07 Mar 1986 03:14
Date: Fri, 07 Mar 1986 03:14
28 lines
1845 bytes
1845 bytes
>/* 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?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads