Question about Const!

  • Thread starter Thread starter Khanh01
  • Start date Start date
K

Khanh01

Guest
Hi, I am reading some const examples C++, and i would like to ask about const in the following procedure.

Here is the code I have:

#include <iostream>
using namespace std;

class Demo {
mutable int i;
int j;
public:
int geti() const {
return i;
}

void seti(int x) const {
i = x; //
}


my question is: What does const in the following line mean? Why is it behind but not in front?

void seti(int x) const

Why this doesn't work?

void setj(int x) const {
j = x; // Still Wrong!
}

Could it be any other keyword besides const? Where can I read more about it.

I have read c ++ basic but I have not encountered this case, please help me this case.

Thanks a lot !

Continue reading...
 
Back
Top