可能重复:
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)
这意味着该函数不能改变任何成员变量.
class A {
void Func() const
{
++mI; // compiler error
}
int mI;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
599 次 |
| 最近记录: |