我一直想知道为什么以下简单的代码在从main()返回时会产生分段错误:
//Produces "Error while dumping state (probably corrupted stack); Segmentation fault"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Test
{
vector<int> numbers;
};
int main()
{
Test a;
ifstream infile;
cout << "Last statement..." << endl; // this gets executed
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有趣的是,1)如果只声明了两个变量中的一个,我没有得到错误,2)如果我声明一个向量变量而不是带有向量成员的对象,一切都很好,3)如果我声明一个ofstream而不是再一次,ifstream,一切正常.这个特定的组合似乎有些不对劲......
这可能是编译器错误吗?我使用gcc版本3.4.4与cygwin.
提前感谢您的提示.
GABOR
c++ ×1