Can you explain surprising C++ parsing?
Much to my surprise, an incorrect copy and paste seems to be legal C++.
Instead of writing
if (my_func())
I accidentally wrote
if (bool my_func())
It seems to compare the function address. Can someone please explain this? I didn't think a function declaration could appear in an expression.
#include <iostream>
bool my_func()
{
return false;
}
int main()
{
if (bool my_func())
std::cout << "true\n";
else
std::cout << "false";
return 0;
}
the output is "true".
Using Microsoft Visual C++ version 6.0