Creating pointer to function instead of object when instentiating with parenthesis

Viewed 23
#include<iostream>

class Foo
{
public:
    int qux(int x);
};

int Foo::qux(int x)
{
    return 2 * x;
}

int main()
{
    Foo foo();
    int a = foo.qux(4);
}

displays the error

Error : expression must have class type but it has type "Foo (*)()"

It would work if I don't use the parenthesis when instantiating foo. But it should also instantiate the object with parenthesis at the end right? Why does it create a function pointer?

0 Answers
Related