std::is_same()
및 typeid()
에 대한 두 개의 테스트 케이스가 있습니다.왜 typeid가 true로 인쇄됩니까?
사례 1 : std::is_same()
#include <iostream>
#include <type_traits>
#include <cstdint>
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_same<int, volatile int>::value << '\n'; // false
}
출력은 :
false
를 그 정확한 출력을 제공한다.
경우 2 : typeid()
#include <iostream>
#include <cstdlib>
using namespace std;
#define CMP_TYPE(a, b) cout<<(typeid(a) == typeid(b)) << endl;
int main()
{
cout << std::boolalpha;
CMP_TYPE(int, volatile int)
}
출력의 경우는 :
true
왜 인쇄 진정한 유형 ID는 무엇입니까?
HTTP : // EN 모든 경우에
유형 ID에 의해 무시됩니다. cppreference.com/w/cpp/language/typeid – Mat
Mat의 링크에서 : "모든 경우에 cv 한정자는'typeid' (즉,'typeid (T) == typeid (const T))'에 의해 무시됩니다. 이 동작이 예상됩니다. – Quentin
"잘못"하지 않았습니다. 다르게 작동하도록 정의되었습니다. 질문을 다시 말하면 실제로 흥미로운 질문 일 수 있습니다. – StoryTeller