나는 다음과 같은 경우 :C++은 멤버 함수의 특정 const를 호출하도록 보장됩니까?
class A {
int foo() const {
j++;
return i;
}
int& foo() {
return i;
}
int i;
mutable int j;
};
다음 분명히 뭔가
A a;
a.foo() = 5;
같이 const가 아닌 버전을 호출합니다. 그러나 조건이 충족 될 필요하면 개체 자체가
const
때
int i = a.foo(); //I would expect to call the const. Is it guaranteed?
const int j = a.foo(); //Ditto
const int& l = a.foo(); //Ditto
int& k = a.foo(); //I would expect the non-const
foobar(k); //foobar is "void foobar(int)"
return; //but the compiler could potentially decide the const version is fine.
'mutable' = 웩한다. EDIT하지만 이걸 찾았 어. http://stackoverflow.com/questions/105014/c-mutable-keyword – rubenvb