I've been wondering why the following trivial code produces a segmentation fault when returning from 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;
开发者_Go百科 ifstream infile;
cout << "Last statement..." << endl; // this gets executed
return 0;
}
Interestingly, 1) if only one of the two variables is declared, I don't get the error, 2) if I declare a vector variable instead of an object with a vector member, everything's fine, 3) if I declare an ofstream instead of an ifstream, again, everything works fine. Something appears to be wrong with this specific combination...
Could this be a compiler bug? I use gcc version 3.4.4 with cygwin.
Thanks for the tips in advance.
Gábor
This is a bug. If this is your entire program, there is absolutely nothing wrong with it. You have discovered a bug in the compiler or standard library. As was recommended to you in the comment, try a 4.x series gcc compiler. The 3.x series is old as the hills.
精彩评论