Re: [ROOT] Cint warnings on const members

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Feb 02 2001 - 18:19:29 MET


Hi Victor,

In a class member function declared const, you can call a non-const
function of the class by a dirty cast. See example below.

CBananaPlant::Function() const {
 ((CBananaPlant *)this)->SomeNonConstFunction();
}

This is a dirty solution, clearly violating the intended security with const.
You better solve the problem with const by making sure that all the class
functions called from a const fonction are also const.
Sometimes, this is useful.

Rene Brun


Victor Krylov wrote:
> 
> Hello everybody,
> 
> I have a class with some const members.
> Somebody knows how to deliver from the warnings?
> 
> BananaPlantCint.cxx: In method `void CBananaEvent::Streamer(class
> TBuffer &)':
> BananaPlantCint.cxx:258: warning: converting to `CBananaPlant *' from
> `const CBananaPlant *' discards const
> BananaPlantCint.cxx:258: warning: initializing non-const `CBananaPlant
> *&' with `const CBananaPlant *' will use a temporary
> BananaPlantCint.cxx:40: warning: in passing argument 2 of `operator
> >>(TBuffer &, CBananaPlant *&)'
> 
> Regards,
>         Viktor



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:35 MET