相关疑难解决方法(0)

为什么允许将自身重新解释为整数,枚举和成员指针类型?

In this recent question, we saw that it's not allowed to reinterpret_cast some custom class type instance to itself; struct A{}; reinterpret_cast<A>(A{}); is invalid (it works only through references or pointers). Which seems to make sense, because of the lack of real-world scenarios where such identity conversion is necessary.

Checking the corresponding standard clause, we have in [expr.reinterpret.cast] (emphasis mine):

1 [...] Conversions that can be performed explicitly using reinterpret_­cast are listed below. No other conversion can be performed …

c++ language-lawyer reinterpret-cast

6
推荐指数
1
解决办法
93
查看次数

标签 统计

c++ ×1

language-lawyer ×1

reinterpret-cast ×1