Why parenthesis after an object variable declaration cause error (C++)?
<p>I created a class which basically serves as a public structure in this example, and let's say the class name is <code>X</code>. I want to declare a local object in main function. The short version of my question is: I know we can do <code>X foo;</code>, but I think <code>X foo();</code> (attach a pair of parenthesis) should work, and I thought the first usage is actually a shorthand of the second usage. The entire code is provided below:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

class X {
    public:
        int val1;
        int val2;
};

int main() {
    X a;
    X b();    // A warning here
    X *c = new X;
    X *d = new X();

    cout &lt;&lt; "val of a: " &lt;&lt; a.val1 &lt;&lt; " " &lt;&lt; a.val2 &lt;&lt; endl;
    cout &lt;&lt; "val of b: " &lt;&lt; b.val1 &lt;&lt; " " &lt;&lt; b.val2 &lt;&lt; endl;    // Compile error
    cout &lt;&lt; "val of c: " &lt;&lt; c-&gt;val1 &lt;&lt; " " &lt;&lt; c-&gt;val2 &lt;&lt; endl;
    cout &lt;&lt; "val of d: " &lt;&lt; d-&gt;val1 &lt;&lt; " " &lt;&lt; d-&gt;val2 &lt;&lt; endl;

    return 0;
}
</code></pre>

<p>And the compiler complains:</p>

<pre><code>11_stack.cpp:16:6: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse]
        X ab();
            ^~
11_stack.cpp:16:6: note: replace parentheses with an initializer to declare a variable
        X ab();
            ^~
            {}
11_stack.cpp:22:26: error: use of undeclared identifier 'b'
        cout &lt;&lt; "val of b: " &lt;&lt; b.val1 &lt;&lt; " " &lt;&lt; b.val2 &lt;&lt; endl;
                                ^
11_stack.cpp:22:43: error: use of undeclared identifier 'b'
        cout &lt;&lt; "val of b: " &lt;&lt; b.val1 &lt;&lt; " " &lt;&lt; b.val2 &lt;&lt; endl;
                                                 ^
1 warning and 2 errors generated.
</code></pre>

<p>My initial guesses are the following:</p>

<ol>
<li>In any case, we shouldn't put an empty parenthesis after a declared variable.</li>
<li>It triggers <code>operator()</code>.</li>
</ol>

<p>But later on I disproved both hypotheses. We can see the first disproof in the code: both <code>X *c = new X;</code> and <code>X *d = new X();</code> work. For the second one, I put additional code like this:</p>

<pre><code>a();
</code></pre>

<p>Then I got compilation error messages:</p>

<pre><code>11_stack.cpp:26:2: error: type 'X' does not provide a call operator
        a();
        ^
</code></pre>

<p>So what exactly cause the error?</p>

<p>Working environment:</p>

<ul>
<li>Mac OS 10.11.3</li>
<li>g++ with flag c++11</li>
<li>Xcode Version 7.2 (7C68)</li>
</ul>

<p>P.S. Please also help me think a better and descriptive post title if it's too ambiguous...</p>