[PATCH] constify some methods
Harri Porten
porten at froglogic.com
Thu Aug 28 21:17:10 BST 2008
Hello Bernhard,
On Thu, 28 Aug 2008, Bernhard wrote:
> while playing with the khtml sources I've fixed some caretPos() methods
> in the rendering directory to be const. At least for me, it helped me
> understand more quickly that none of these methods will have side
> effects on their objects, as the const keyword provided evidence. So I
> figured I'd share the patch with you. Feel free to apply it in the
> khtml/rendering directory.
Thank's for the patch. I'll apply it short - with the exception of one
case (turning up twice) that I suggest to better not change the signature
of:
-InlineTextBox * RenderText::findInlineTextBox( int offset, int &pos, bool
checkFirstLetter )
+InlineTextBox * RenderText::findInlineTextBox( int offset, int &pos, bool
checkFirstLetter ) const
There are different opinions out there whether a method should be const or
not. The C++ spec gives away that it influence "this". From that one can
deduct that a function may not modify the object. But that does not only
involve direct write access. It could happen through the detour of e.g. a
pointer (like InlineTextBox*) that allows modifying the object. What
relationship the pointer and object have could be dependant on the case.
I've not checked this one so I would ommit those two chunks unless
convinced otherwise. Or maybe the function can also be changed to return
"const InlineTextBox*"?
Harri.
P.S. Here is where I wrote up some thoughts on this topic once:
http://www.froglogic.com/~porten/const.html
More information about the kfm-devel
mailing list