main
함수에서 으로 선언 된 변수에 const int
포인터 변수를 할당했습니다. 그런 다음 decltype(x)
을 사용하여 유형을 확인하십시오. 유형이 const int*
일 것으로 예상했습니다. 그러나 is_same
은 false
을 반환합니다.유형이 auto & x = const int *입니까?
int main()
{
int a = 10;
const int * cp_val= &a;
auto& x = cp_val;
bool is_const_int_ptr = std::is_same<decltype(x), const int *>::value; // returns 0
// *x = 100; // error: assignment of read-only location '* x'
}
하지만 다음 도우미 기능을 추가하는 경우 : 주에서
#include <boost/type_index.hpp>
template<typename T>
void print_type(T)
{cout << "type T is: "<< boost::typeindex::type_id_with_cvr<T>().pretty_name()<< '\n';}
을, 나는 기능
print_type(x); // It returns int const*
내가 std::is_same
에서 뭔가를 놓치고 있습니까 호출?