在一个非模板类中,是否有理由更喜欢以
此外,我们也关心函数是否被定义为const时是否有所不同:
const <type>& foo();
形式返回函数的返回值类型,而不是<type> foo();
?这里的<type>
是一个内在类型。如果<type>
是一个类/结构体对象呢?此外,我们也关心函数是否被定义为const时是否有所不同:
const <type>& foo() const;
与<type> foo() const;
例如,在一个非模板类的非模板函数中:const int& foo() const { return member_variable_; }
对比
int foo() const { return member_variable_; }