 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Daryle Walker Guest
|
Posted: Fri Oct 31, 2003 2:59 am Post subject: Quick question on de-const-ing |
|
|
I'm going to have a pointer to a const object (T const *), it's going to
be dereferenced in a read-only manner, but the interface function takes
a pointer to a non-const (U f(T *x)). I can use a const_cast without
any new worries, right?
There's another part of the library that could write through that
pointer. As long as my wrapping code blocks all the potential writing
calls, I have nothing to worry about, right?
(I've thought of evil hacks that can get around my blocks, which I
cannot counter-block. But I shouldn't let those bother me too much;
should I follow "protect against Murphy, not Machevelli"? I should have
less to worry about; the default implementations of the writing calls
just return error codes, I would have to do virtual overrides to
activate/add writing; so I just don't add those overrides. Now you can
see the evil hack, just subclass my leaf class and add the evil
write-activation overrides.)
--
Daryle Walker
Mac, Internet, and Video Game Junkie
dwalker07 AT snet DOT net
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thomas Richter Guest
|
Posted: Sat Nov 01, 2003 9:57 am Post subject: Re: Quick question on de-const-ing |
|
|
Hi,
| Quote: | I'm going to have a pointer to a const object (T const *), it's going to
be dereferenced in a read-only manner, but the interface function takes
a pointer to a non-const (U f(T *x)). I can use a const_cast without
any new worries, right?
|
Right. (Except maybe that you might want to change that interface. If
there is read-only access, then what's the point of not making it
const?)
| Quote: | There's another part of the library that could write through that
pointer. As long as my wrapping code blocks all the potential writing
calls, I have nothing to worry about, right?
|
Right, but see above. What do you mean by "blocks all the potentional
writing"? You mean that you can ensure that the writings never take place
by apropriate side conditions, I assume?
So long,
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|