Method declaration and const

Hi everybody,
I am new here. Nice to join our forum.
I have a question:
virtual void solve() const { }
What does this method do with const?
Thanks you in advance.

Last edited on
The const means that the function promises not to change any member variables. That can be overridden by declaring the such a variable as mutable.
It means that it doesn't modify the object from which is called ( so you can call it from const objects
eg:
1
2
3
4
5
6
7
8
9
struct Class
{
    void A() {} // not const
    void B() const {}
};

const Class object;
object.A(); // ERROR
object.B(); // OK 
Topic archived. No new replies allowed.