【发布时间】:2013-10-19 21:00:51
【问题描述】:
我知道我们什么时候使用
int func() const;
那么我们不能修改函数中的任何东西,除了可变变量。 但是当我使用
const int func();
它允许我修改任何东西?
【问题讨论】:
我知道我们什么时候使用
int func() const;
那么我们不能修改函数中的任何东西,除了可变变量。 但是当我使用
const int func();
它允许我修改任何东西?
【问题讨论】:
const int func();
是返回const int和
int func() const;
是const 函数,即不修改对象状态的函数,在该函数上调用它。
【讨论】:
const 值。不要与返回 const 引用混淆,它的语义与返回 (const) 值有很大不同。