Search code examples
c++pointersintegertype-conversionreinterpret-cast

Why can reinterpret_cast not convert an int to int?


My compiler is the latest VC++ 2013 RC.

void f()
{
    int n1 = 0;
    int n2 = reinterpret_cast<int>(n1); // error C2440
}

error C2440: 'reinterpret_cast' : cannot convert from 'int' to 'int'

Why can reinterpret_cast not be used in such an obvious case?


Solution

  • According to cppreference.com the following conversion is available only since C++11:

    An expression of integral, enumeration, pointer, or pointer-to-member type can be converted to its own type. The resulting value is the same as the value of expression.

    which may not be implemented in Visual Studio 2013 RC yet.