D
deancoo
Ok, I've got another one for ya. The code I've pasted below compiles fine
but produces a seg fault. I've put a comment in where the seg fault gets
tripped. Can someone please explain what I've done wrong. Thanks again for
any help.
d
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class hand {
public:
vector<int> my_ints;
};
class hand_vector {
public:
vector<hand> myhands;
};
int main(int argc, char *argv[])
{
system("PAUSE");
hand_vector *myvector;
hand v_stub;
for (int i=1; i<=10; i++) {
myvector->myhands.push_back(v_stub); // SEGMENTATION FAULT HERE
};
system("PAUSE");
vector<hand>::iterator j;
for (j=myvector->myhands.begin(); j!=myvector->myhands.end(); j++) {
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
};
system("PAUSE");
delete myvector;
system("PAUSE");
return EXIT_SUCCESS;
}
but produces a seg fault. I've put a comment in where the seg fault gets
tripped. Can someone please explain what I've done wrong. Thanks again for
any help.
d
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class hand {
public:
vector<int> my_ints;
};
class hand_vector {
public:
vector<hand> myhands;
};
int main(int argc, char *argv[])
{
system("PAUSE");
hand_vector *myvector;
hand v_stub;
for (int i=1; i<=10; i++) {
myvector->myhands.push_back(v_stub); // SEGMENTATION FAULT HERE
};
system("PAUSE");
vector<hand>::iterator j;
for (j=myvector->myhands.begin(); j!=myvector->myhands.end(); j++) {
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
};
system("PAUSE");
delete myvector;
system("PAUSE");
return EXIT_SUCCESS;
}