c++函数名后面带有const的含义

c++的函数中, const可以在函数名前, 也可以出现在函数名后,

# 出现在函数名前

int const value(){};
1

const出现在函数名前是为了修饰返回值

# 出现在函数名后

class Foo(){
public:
    int value() const{};
}
1
2
3
4

const出现在函数名后, 说明函数不能修改class成员变量, 对class成员变量只能进行读操作

Last Updated: 2022/8/4 上午12:40:11