Hi everyone :)
i'm writing a scheduling programm and i can't solve this problem: when i run the input driver(which is suppose to initialize a vector of objects with the information contained in a file), it gives me a Segmentation fault(core dumped error) and i don't know why.
#include ....
int main()
{
vector<MachineFamily> mf;
int num_families;
MachineFamily f;
ifstream is ("families.txt");
is >> num_families;
for (int i = 0; i < num_families; i++)
{
is >> f;
mf.push_back(f);
}
is.close();
return 0;
}
i don't know what to do.. i think the problem id in operator>> but i don't know how to solve it.
Hope i've explained myself well...
Can someone help me please?
I did not get seg fault, but think that the reading was off.
The size of the MachineFamily::machines vector did not correspond with the MachineFamily::num_machines.
The vector was increasing from the previous readings, you need to clear it first.
Ditto for `tips'
Also, limit the scope
1 2 3 4 5 6
for (int i = 0; i < num_families; i++)
{
MachineFamily f;
is >> f;
mf.push_back(f);
}
I've found the problem!! It's the copy constructor MachineFamily(const MachineFamily& f). It's enough to remove it and I don't have the error msg anymore!!!