#include <iostream>
struct Foo
{
Foo(int d) : x(d) {}
int x;
};
int main()
{
double x = 3.14;
Foo f( int(x) );
std::cout << f.x << std::endl;
return 0;
}
When I compile this code I get the following error:
[Error] request for member 'x' in 'f', which is of non-class type 'Foo(int)'
Suppose that in int main
I remove int
in Foo f(int(x))
.
I mean if I write just like this:
Foo f(x);
the code compiled correctly and got the output as 3.
So what happens if we type cast the argument like Foo f(int(x)) to invoke the constructor?