当你的函数名和输入后有"const"时,它是什么意思?

vvM*_*Ovv 1 c++

可能重复:
const表示函数/方法签名后的含义是什么?

继续笑我,但函数后的const表示什么?

int someFunc() const{  //<<----notice the const
    //insert code  blah...
}
Run Code Online (Sandbox Code Playgroud)

如果我想要返回类型的const int,我不会写

const int someFunc(){
    //code....
}
Run Code Online (Sandbox Code Playgroud)

axo*_*xon 5

这意味着该函数不能改变任何成员变量.

class A {
void Func() const
{
  ++mI; // compiler error
}
int mI;
};
Run Code Online (Sandbox Code Playgroud)