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;
isconst
函数,即不修改对象状态的函数,该函数已被调用。作为旁注,与问题几乎无关,但仍然值得一提,返回const
值是不受欢迎的,因为我们有了移动语义(因为它禁止移动)。不要与返回const
引用相混淆,该引用与按(const
)值返回具有非常不同的语义。
int func() const;