c++ - const int function(); 之间的区别和 int func() 常量;

标签 c++ function constants

我知道什么时候用

 int func() const;

then we cannot modify anything in the function except for mutable variable. But when i used

const int func();

它允许我修改任何东西吗?

最佳答案

const int func();

是返回 const int

的函数
int func() const;

const 函数,即不修改对象状态的函数,它已被调用。

关于c++ - const int function(); 之间的区别和 int func() 常量;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471098/

相关文章:

c++ - 排列 +ve 和 -ve 数字的数组,顺序不变

c++ - 将函数包装器转换为 std::function

java - 如何在java中的const变量中保存Date对象

c++ - 为什么 "const T*"在 "void*"中被简单地转换为 "operator delete"?

c++ - 多个文件中的常量定义

c++ - 在 C++ 代码中使用 '$' 符号安全吗?

c++ - 在 MFC 中使用静态库

c++ - 将 std::tr1::shared_ptr 与 std::function/std::bind 混合会导致较新的 gcc 出现编译器错误

c++ - 将 vector 作为函数参数传递

python - 在 Python 中的 `for` 循环中定义函数时出现问题