z*y 发帖数: 1311 | 1 const int &func (int a, int b) const;
what is the meaning of first "const" and last "const"?
what is the meaning of "&"? |
d**********x 发帖数: 4083 | 2 ...
【在 z*y 的大作中提到】 : const int &func (int a, int b) const; : what is the meaning of first "const" and last "const"? : what is the meaning of "&"?
|
H****s 发帖数: 247 | 3 This function returns a constant integer reference, this member function is
a constant function that won't change any member variables of the associated
class. |
w**s 发帖数: 339 | |
A*****i 发帖数: 3587 | 5 一直认为函数前的const绝对是有人故意造出来害人的,因为完全没有用处。貌似C++
prime也提过这个,但是每次面试总考,这绝对是个阴谋 |
l*********u 发帖数: 19053 | 6 同意。
return constant的function,应该是某个"蛋疼帝"想出来滴 :)
【在 A*****i 的大作中提到】 : 一直认为函数前的const绝对是有人故意造出来害人的,因为完全没有用处。貌似C++ : prime也提过这个,但是每次面试总考,这绝对是个阴谋
|
q****m 发帖数: 177 | 7 c++ overloading 不检查 return type 吧。
【在 l*********u 的大作中提到】 : 同意。 : return constant的function,应该是某个"蛋疼帝"想出来滴 :)
|
H****s 发帖数: 247 | 8 你们错了, 这里我只举一个简单例子说明一下,return constant reference
绝对不是多此一举。
class A{
Object theObj;
public:
const Object & getTheObj(); //the Obj won't get changed when calling this
//function
};
【在 l*********u 的大作中提到】 : 同意。 : return constant的function,应该是某个"蛋疼帝"想出来滴 :)
|