std::is_void
的描述指出:
如果 T 是 void、const void、volatile void 或 const volatile void 类型,则提供等于 true 的成员常量值。
那么什么可能是 const void
或 volatile void
?
这个答案 指出 const void
返回类型将是无效的(但是在 VC++ 2015 上编译)
const void foo() { }
如果按照标准, const void
无效(VC 错误) - 那么 const void
是什么?
原文由 Ajay 发布,翻译遵循 CC BY-SA 4.0 许可协议
const void
是一种可以形成指针的类型。它类似于普通的 void 指针,但转换的工作方式不同。例如const int*
不能隐式转换为void*
,但可以隐式转换为const void*
。 Likewise, if you have aconst void*
you cannotstatic_cast
it to anint*
, but you canstatic_cast
it to aconst int*
.