The other day i was trying to create an object by calling the default constructor of another class, and it ended up making a function declaration, Here is an example:
struct integer {
integer(){} //Default constructor.
};
struct rational {
rational(integer n, integer d){} //Default constructor.
};
void multiply(rational(), rational()) { //Valid syntax? Takes two function pointers.
}
rational one_half() {
return rational(integer(), integer()); //Here doesnt make a function declaration.
}
int main() {
rational num(integer(), integer()); //Here makes a function declaration,
//instead of constructing a rational object.
multiply(one_half, one_half); //function taking two function pointers.
}
Why does this happen? I know and can call the constructor like this integer::integer()
but i would like to understand what's happening here and why integer()
is behaving like integer(*)()
in this example.