Code:
#include <iostream>
class Foo{
int t;
public:
Foo(int t=0):t(t){}
void show(){
std::cout << t;
}
};
void Func(Foo foo){
foo.show();
}
int main(){
Func(0);
return 0;
}
Output: 0
So apparently when I pass an integer to a function that's supposed to take a Foo type argument, it somehow converts it to Foo(and even takes the integer as a constructor parameter) and works fine. I guess it has something to do with the way constructor works, but I really don't understand why it works that way. I researched a lot but couldn't find anything about it. Any thoughts?