C样式的指针查询到C ++类型转换

时间:2014-06-17 04:22:59

标签: c++

typedef uint8_t RANGE;

int main()
{    
   const  uint16_t  FREQ_RATED_MIN_VALUE = 54;

   RANGE* min;

   min = (uint8_t*)&FREQ_RATED_MIN_VALUE; // C style tyecast

   cout << min << endl; // prints value

   min = reinterpret_cast<uint8_t*>(&FREQ_RATED_MIN_VALUE); //ERROR to be removed in this statement to be written in C++ style typecast

   return 0;
}

需要帮助在声明中注释C ++样式的类型转换..

1 个答案:

答案 0 :(得分:0)

您的演员会放弃const资格。使用C ++样式转换来转换constness需要const_cast。试试这个:

min = reinterpret_cast<uint8_t*>(const_cast<uint16_t*>(&FREQ_RATED_MIN_VALUE));