Re: const-correct smartpointers
- From: Bowie Owens <bowie owens csiro au>
- To: Murray Cumming Comneon com, orbitcpp-list gnome org
- Subject: Re: const-correct smartpointers
- Date: Mon, 02 Jun 2003 14:33:17 +1000
Hi Murray,
Unfortunately, your changes don't work for me. When I have const _var
object and try and cast it to a _ptr I get errors.
I am not familiar with MICO, but omniORB has a simple approach to avoid
the warnings. In omniORB, rather than provide two operators (and thus
cause GCC to complain) they only provide one. The const one. Also,
rather than return a reference to a pointer, they just copy it. The code
before your changes was:
operator O_ptr &() {
return m_objectref;
}
operator O_ptr const &() const {
return m_objectref;
}
To follow the omni approach the two operators would then become:
operator O_ptr () const {
return m_objectref;
}
This allows const correct behaviour. It avoids the warnings. Plus it
gets rid of that weird first operator which lets you modify m_objectref
without respecting memory management.
The reason I didn't suggest this earlier is because the C++ mapping spec
I got of the OMG website has both the above operators in its sample code
(section 1 page 13). Also TAO has both operators in its implementation.
I thought it might have something to do with the standard (I don't have
a good reference). But if omni doesn't have the non-const operator maybe
it should be dropped from orbitcpp.
What do you think?
Murray Cumming Comneon com wrote:
I applied a temporary, and maybe useless, fix to ObjectPtr_var<>, to avoid
the masses of warnings:
http://cvs.gnome.org/lxr/source/orbitcpp/orbitcpp/orb-cpp/smartpointers/obje
ctptr_var.h#36
http://cvs.gnome.org/lxr/source/orbitcpp/orbitcpp/orb-cpp/smartpointers/obje
ctptr_var.h#93
To have proper const-correctness I think we need to avoid specifying the
pointer type to the template. See the comments for more clues. The
equivalent in mico doesn't seem to need to do this.
Murray Cumming
murrayc usa net
www.murrayc.com
_______________________________________________
orbitcpp-list mailing list
orbitcpp-list gnome org
http://mail.gnome.org/mailman/listinfo/orbitcpp-list
--
Bowie Owens
CSIRO Mathematical & Information Sciences
phone : +61 3 9545 8055
fax : +61 3 9545 8080
mobile : 0425 729 875
email : Bowie Owens csiro au
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]