Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有这个代码:
void a() { } int main(){ a(); (****&a)(); return 0; }
该语句如何发生(****&a)();与 相同的效果a();?
(****&a)();
a();
这完全是因为函数到指针的转换(§4.3):
函数类型的左值T可以转换为“指针T”类型的纯右值。结果是指向函数的指针。
T
&a首先给你一个指向a. 然后你通过*给你函数本身来取消引用它。然后您尝试取消引用该函数,但由于您不能,它会进行函数到指针的转换以再次获取指针。您使用 取消引用该指针*,依此类推。
&a
a
*
最后(****&a)表示函数a并调用它,因为您可以应用()到函数而无需进行函数到指针的转换。
(****&a)
()