Method overloading with const/non-const variants (was: Re: KDE/kdelibs/kdecore)

Thiago Macieira thiago at
Tue Jul 8 17:19:41 BST 2008

Richard Dale wrote:
>I think it is great that people can understand these rules, and manage
> to write code where they understand how it works. But personally I wish
> we didn't use const overloading in KDE libs unless absolutely
> necessary. There are no other languages apart from C++, that use const
> overloading as far as I know, and it makes it awkward for language
> bindings.


In case of const overloading, there should be a constFoo function that is 
const only, so that you can access it from other languages too, as well 
as making code clearer.

Anyways, you can always call the const function if you want by making your 
object const too:

	Object *foo;
	const Object *constFoo = foo;

	Object foo;
	const Object &constFoo = foo;

This can be done even in the binding.

  Thiago Macieira  -  thiago (AT) - thiago (AT)
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list