为什么投射不成功
Why cast does not succeed?
我正在尝试这个:
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)));
这是一个
疏忽:
只需强制转换为 T 而不是 T 即可工作,因为该函数返回右值并且不能绑定到左值。
相关文章:
- cmake在我的项目中所需的所有静态库都不成功
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 而循环:简单的除法程序输出零,不明白为什么
- 不理解为什么代码没有产生所需的答案
- 我不知道为什么这段代码会让核心被转储?
- 我不明白为什么我的代码不起作用并且需要更长的时间来运行
- C++复制 c'tor 现在确实会采取行动。 不清楚为什么
- 反转字符串.不知道为什么这个逻辑是错误的.C++
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- 什么是非营利组织???我的问题是我不明白为什么有人会使用它
- 我正在尝试用 c++ 制作菜单,但不明白为什么它不循环
- if-else 语句仅按特定顺序工作,我不知道为什么
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 我的程序不适用于 strcat - 我似乎不明白为什么?
- 我不确定为什么代码没有运行,它在编译时抛出错误,说它无法找到 PrintArray()
- 函数抛出seg错误,我不知道为什么
- 我不知道为什么复制构造函数的调用在 c++ 中不稳定
- 为什么这个文件不成功读取
- 为什么投射不成功