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条目也应该有用.
| 归档时间: |
|
| 查看次数: |
328 次 |
| 最近记录: |