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 foo(){ } //... std::cout<<foo<<std::endl;
无论传递的函数如何,这往往会打印出“1”。
现在我很好奇:这到底是做什么的?
foo正在衰减为函数指针,然后将其转换为值为 true 的布尔值(因为函数指针不为空),打印为“1”,因为布尔值默认打印为数字。
foo
尝试这个:
std::cout << std::boolalpha << foo << std::endl;