Hello everyone!..I have a problem with I/O as i try to read/write a complex object from/to a file,but it throws me segmentation fault during the execution of the program.No compile errors.More specifically i have a class MainSystem which includes an array of Store Objects(another complex class) and an array of CLientDB objects.Each of the above two classes has a number of primitive-type variables and other objects variables.In my way,i created a function on the MainSystem class which is below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void MainSystem::saveStateToDisk()
{
ofstream out;
out.open("log.dat",ios::out|ios::binary);
if(!out)
cout<<"File not open"<<endl;
else
{
out.write((char*)&store,sizeof(Store)); //Store Object
out.write((char*)&database,sizeof(ClientDB)); //CleintDb Object
out.write((char*)&rents,sizeof(struct rentInfo*)*rentSize); //array of structs
out.write((char*)&rentSize,sizeof(int));
out.write((char*)&rented,sizeof(Multimedia*)*multimediaRentedSize); //Array of pointers to Multimedia objects
out.write((char*)&multimediaRentedSize,sizeof(int));
out.close();
}
}
In the main.cpp i created the loadFromDisk function:
As i said above,no compile errors.During debugging though i noticed that the program crashes during the setup of the productstore.I would expect it to crash in the previous line during the setup of the ClientDB object but it didn't.Any ideas of how to solve this problem?