Hi

I have 2 classes Person and Car

class CPerson
{
public:
CPerson();
virtual ~CPerson();
void getData(void) {
cout << "Name : " ; cin >> name;
cout << "Age : " ; cin >> age;
}

void showData(void)
{
cout << "\n Name : " << name;
cout << "\n Age : " << age;
}

public:
int age;
char name[14];
CCar itsCar;

};

class CCar
{
public:
CCar();
virtual ~CCar();

public:
int year;
char model[10];

};

Here is my main

#include "stdafx.h"
#include "Person.h"

int main(int argc, char* argv[])
{
CPerson pers;

pers.getData();

pers.itsCar;

cout << "Car Year : " ; cin >> pers.itsCar.year;
cout << "Car Model : " ; cin >> *pers.itsCar.model;

ofstream outfile("person.dat", ios::binary);
outfile.write( (char*) &pers, sizeof(pers));


CPerson me;

ifstream infile("person.dat", ios::binary);

infile.read( (char*) &me, sizeof(me));
me.showData();
cout << "\nCar Model : " << *me.itsCar.model;
cout << "\nCar Year : " << me.itsCar.year;

return 0;
}


I want to serialize Person and itsCar, I can save properly but how can I restore itsCar.

itsCar was a pointer before I changed it to object.

I can not restore the related car.

I have tried to serialize CPerson only and it worked.

AnyOne can help please!

Your help will be rated.

PS : I am not using MFC