C++ 差分b/w常量int func();和int func()常量;

C++ 差分b/w常量int func();和int func()常量;,c++,function,constants,C++,Function,Constants,我知道我们什么时候用 int func()常量 那么除了可变变量之外,我们不能修改函数中的任何内容。 但是当我使用const int func()时 const int func(); 它允许我修改任何东西 const int func(); 返回const int和 int func() const; isconst函数,即不修改对象状态的函数,该函数已被调用。作为旁注,与问题几乎无关,但仍然值得一提,返回const值是不受欢迎的,因为我们有了移动语义(因为它禁止移动)。不要与返回cons

我知道我们什么时候用

int func()常量

那么除了可变变量之外,我们不能修改函数中的任何内容。 但是当我使用
const int func()时

const int func();
它允许我修改任何东西

const int func();
返回
const int

int func() const;

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

作为旁注,与问题几乎无关,但仍然值得一提,返回
const
值是不受欢迎的,因为我们有了移动语义(因为它禁止移动)。不要与返回
const
引用相混淆,该引用与按(
const
)值返回具有非常不同的语义。
int func() const;