为什么在使用()用于声明对象时不调用构造函数?

Laz*_*zer 11 c++ constructor most-vexing-parse

可能重复:
为什么使用一组空括号来调用没有参数的构造函数是错误的?

$ cat cons.cpp
#include <iostream>

class Matrix {
private:
    int m_count;

public:
    Matrix() {
        m_count = 1;
        std::cout << "yahoo!" << std::endl;
    }
};

int main() {
    std::cout << "before" << std::endl;
    Matrix m1();                         // <----
    std::cout << "after" << std::endl;
}
$ g++ cons.cpp
$ ./a.out
before
after
$
Run Code Online (Sandbox Code Playgroud)

语法是Matrix m1();做什么的?

我相信它是一样的Matrix m1;.显然我错了.

Mah*_*esh 12

Matrix m1(); // m1 is a function whose return type is Matrix.
Run Code Online (Sandbox Code Playgroud)

此C++ FAQ lite条目也应该有用.

List x之间有什么区别; 和列表x();