【发布时间】:2012-03-16 02:58:57
【问题描述】:
可能重复:
Why is it an error to use an empty set of brackets to call a constructor with no arguments?
$ 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
$
Matrix m1(); 的语法有什么作用?
我相信它和Matrix m1;是一样的。显然我错了。
【问题讨论】:
标签: c++ constructor most-vexing-parse