Saving objects to disk

E

Eagle

Hi,

I'm sure I learnt this at college but have now forgotten ......

I need to save the following to file:

class Company {
private:
char name[50];
// etc..
Contact* con;
public:
// various accessors and modifiers etc
}

The contact class is a simple name and phone no. stuff.

I can read the Company class (without the Contact pointer) to file
(ios::binary) and read them all back into a linked list. But if I include
the Contact stuff, it is all screwed - prob because I'm storing the pointer
.......

So how does one save to file objects that contain other objects (either via
association or containment ...)?

Thanks
 
V

Victor Bazarov

Eagle said:
I'm sure I learnt this at college but have now forgotten ......

I need to save the following to file:

class Company {
private:
char name[50];
// etc..
Contact* con;
public:
// various accessors and modifiers etc
}

The contact class is a simple name and phone no. stuff.

I can read the Company class (without the Contact pointer) to file
(ios::binary) and read them all back into a linked list. But if I include
the Contact stuff, it is all screwed - prob because I'm storing the pointer
......

So how does one save to file objects that contain other objects (either via
association or containment ...)?

My guess would be that one needs to provide a special way. Have you
read the FAQ section on serialisation? It's a new section. Please
do take a look. http://www.parashift.com/c++-faq-lite/

Victor
 
C

Chris Theis

Eagle said:
(either

Thanks guys ... will do ... I thought serialisation was only available in
Java ..... :)

Nope, serialization is rather a concept than a language specific feature.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top