extragear/multimedia/amarok/src

Jeff Mitchell kde-dev at emailgoeshere.com
Thu Oct 23 01:24:16 CEST 2008


Erik Hovland wrote:
> SVN commit 874243 by hovland:
> 
> Remove unneeded const.
> 
> When there is a const at the end of a function declaration. For example:
> QString foo() const {}
> 
> Then a const at the beginning is unneeded:
> const QString foo() const {}

This is not true.

A const at the end of a function declaration means that no member
variables will be changed inside the function.

A const at the beginning means that the returned object is const, i.e.
is not allowed to be modified.

Some examples:

Object* getObject() const { return &m_object; } //valid
Object * getObject() const { m_object++; return &m_object; } //illegal

const Object* getObject() { return &m_object; } //valid
const Object * getObject() { m_object++; return &m_object; } //valid

const Object * getObject() { m_object++; return &m_object; }
const Object* myObj = getObject(); myObj = otherObj; //illegal
Object* myObj = getObject(); //illegal, would need to const_cast

See also http://developer.kde.org/~wheeler/cpp-pitfalls.html#const , do
a search for "Specifically all of the following cases are different"

Please revert this patch.

Thanks,
Jeff


More information about the Amarok-devel mailing list