为什么强制转换不成功?

问题描述 投票:1回答:1

我正在尝试:

 if constexpr (Bo == ByteOrder::Network && sizeof(T) == 8)
    return reinterpret_cast<T &> 
  (be64toh(reinterpret_cast<make_unsigned_t<T>&>(val)));
 else if constexpr (Bo == ByteOrder::Host && sizeof(T) == 8)
    return reinterpret_cast<T &>(htobe64(reinterpret_cast<make_unsigned_t<T>&>(val)));

结果为:

error: invalid cast of an rvalue expression of type ‘__uint64_t {aka long unsigned int}’ to type ‘long int&’
     return reinterpret_cast<T &>(be64toh(reinterpret_cast<make_unsigned_t<T>&>(val)));
c++ linux endianness
1个回答
0
投票

这是一个疏忽:

© www.soinside.com 2019 - 2024. All rights reserved.