decltype(void())和decltype(void {})之间的差异 [英] Differences between decltype(void()) and decltype(void{})
问题描述
这是此问题的后续问题: 它们之间有什么区别(在 为了完整性,它遵循一个最小(not-)工作示例: 我认为 This is a follow-up of the question: What does the What's the difference between them (in the context of a For completeness, it follows a minimal (not-)working example:
I don't think 这篇关于decltype(void())和decltype(void {})之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
在
中的 c(c)>
$ b
decltype(void())
编译良好, void()
意味着在这种情况下在上面提到的问题(实际上在答案中)中解释。
另一方面,我注意到 decltype (void {})
不编译。
至少)?
为什么不编译第二个表达式?
int main(){
// this does not compile
// decltype(void {})* ptr = nullptr;
//这个编译好
decltype(void())* ptr = nullptr;
(void)ptr;
}
与
被解释为type-id。 sizeof
一起使用时,void()
void与
被解释为一个表达式。 decltype
一起使用时,
void {}
在任何上下文中都有效。它既不是有效的类型ID也不是有效的表达式。void()
in decltype(void())
mean exactly?.
decltype(void())
compiles fine and what the void()
means in this case is explained in the above mentioned question (actually in the answer).
On the other side, I noticed that decltype(void{})
doesn't compile.decltype
at least)?
Why doesn't the second expression compile?
int main() {
// this doesn't compile
//decltype(void{}) *ptr = nullptr;
// this compiles fine
decltype(void()) *ptr = nullptr;
(void)ptr;
}
void()
is interpreted as type-id when used with sizeof
.
void()
is interpreted as an expression when used with decltype
. void{}
is valid in any context. It is neither a valid type-id nor a valid expression.