<分区>
Possible Duplicate:
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;
相同。显然我错了。