k
및 k2
은 모두 const int&
유형입니다.
다음은 전체 유형 목록입니다. 최고 수준 const
은 auto
유형 공제에 대해 삭제됩니다.
int main()
{
const int i = 42;
auto j = i; // i is an int (const is top-level)
const auto &k = i; // k is a const int&
auto *p = &i; // p is a const int* (const persists as not top-level).
const auto j2 = i, &k2 = i; // j2 is a const int, k2 is a const int&
}
마지막으로, 만약 당신이 다음
auto q = &k2;
를 기록했던
const
최상위 때문에 폐기되지 않고
auto
유형 공제가되지 않기 때문에
q
의 종류는
const int*
입니다. 이것은 당신이 관찰 한 디버그 정보를 복구합니다.
j2
및 k2
은 비슷하지 않지만 실제로는 선언이 쉼표로 작동하는 방식 때문입니다 (cf. 혼란은 당신은 항상 확인이 C++ 11 표준 라이브러리 함수 is_same
을 사용하기위한 찾을 수
const int j2 = i, &k2 = i;
를 작성하여 실을 뽑아 푼 수 있습니다 예를 들어, decltype
는 인수의 유형를 복구
bool am_I_the_same = std::is_same<decltype(k2), const int&)::value
.
참조 : http://en.cppreference.com/w/cpp/types/is_same
질문은 ...? :) – Pierre
질문은 왜 & k와 & k2가 다른 유형입니까? –
& k와 & k2가 다른 유형인지 어떻게 알 수 있습니까? – cpplearner