> class X
{
void foo() const;
void goo();
}
suppose that foo() and goo() has exactly the same content, is foo() faster
than goo()? what does compiler optomization does to const function?
Not very likely, the foo() is possible to call for const objects of type X,
that's the primary purpose of it in this context. It also makes the object
const for duration of the method call, so you cannot write to members or
call non-const methods, so it's more of static compilation-time const
enforcement tool than anything else.
The primary use (in practise, personal observation only) is to allow to
query state from const objects, along the lines of:
void bar(const object& x)
{
int v = x.foo();
...
... in this light having a const method, foo(), like you have above without
return value or arguments is a bit useless, unless the method does something
with static member, global variable or function or something similiar. But
it will have very little to do with the current object, it can't really do
anything to it without mutable members in the object (or some other cases
that don't spring to mind immediately :)
... useless answer? I think so, too, but that's the thoughts that passed
through my mind as of few minutes ago. :)