Re: Core bug, and ebnc bug when handling the core bug

"A. Craig West" <[email protected]> Tue, 23 Mar 2004 13:57:23 -0500 (EST)
Newsgroups gmane.network.everybuddy.devel
Message-ID <[email protected]>
On Tue, 23 Mar 2004, Karine Proot wrote:

> On Sun, 2004-03-21 at 17:15, Cory McWilliams wrote: 
> > This kind of thing works fine for me.
> > 
> > class Tab
> > {
> > 	/* ... */
> > 	Tab *getPrevious() const;
> > 	/* ... */
> > };
> > 
> > Tab *Tab::getPrevious() const
> > {
> > 	/* ... */
> > }
> I am very surprised it works for you. Somebody explained to me that the
> const is strongly enforced in C++. If you are going to return a 
> pointer to a member from a const method, it has to be const. So I have
> to write:
>    const Tab *getPrevious() const;
> 
> but then, I get many
>    invalid conversion from `const Tab*' to `Tab*'
> 
> so I have to decide now if it's worth it... if I don't do it now it will
> be even more painful later.

For things like this, it's usually a good idea to have both a const and a
non-const getter, and to try to use const references and pointers whenever
possible. Of course, for a Const Tab* to be useful, it needs to have as many
const methods as possible too :-) It really is worthwhile in the long run,
but is much easier to do when the whole thing is written with const in mind
from the beginning...

-- 
Craig West         Ph: (416) 666-1645	|  It's not a bug,
[email protected]              	|  It's a feature...