I could not understand the second foo call in the code below. How does it call global foo function. Why does (foo) call struct A's int()? Can you help me?
#include <stdio.h>
#include <utility>
#include <iostream>
using namespace std;
namespace MySpace{
struct A{
operator int () const {
cout <<"operator" << endl;
return 1;
}
};
void foo(A){
std::cout<< "1" << endl;
}
}
void foo(int){
std::cout << "--2" << endl;
}
int main()
{
MySpace::A x;
foo(x);
(foo)(x);
return 0;
}
I could not understand the second foo call. How does it call global foo function. Why does (foo) call struct A's int()? Can you help me?