473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Saving objects to disk

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
Jul 22 '05 #1
4 4451
"Eagle" <ne**@eagle136.fsnet.co.uk> wrote...
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
Jul 22 '05 #2
Eagle wrote:
So how does one save to file objects that contain other objects (either via
association or containment ...)?

Serialization, read all about it:
http://www.parashift.com/c++-faq-lit...alization.html


Brian Rodenborn
Jul 22 '05 #3

"Default User" <fi********@boeing.com.invalid> wrote in message
news:40***************@boeing.com.invalid...
Eagle wrote:
So how does one save to file objects that contain other objects (either via association or containment ...)?

Serialization, read all about it:
http://www.parashift.com/c++-faq-lit...alization.html


Brian Rodenborn


Thanks guys ... will do ... I thought serialisation was only available in
Java ..... :-)
Jul 22 '05 #4

"Eagle" <ne**@eagle136.fsnet.co.uk> wrote in message
news:bv**********@news6.svr.pol.co.uk...

"Default User" <fi********@boeing.com.invalid> wrote in message
news:40***************@boeing.com.invalid...
Eagle wrote:
So how does one save to file objects that contain other objects
(either
via association or containment ...)?

Serialization, read all about it:
http://www.parashift.com/c++-faq-lit...alization.html


Brian Rodenborn


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


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

Chris
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
2
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
0
by: Nate | last post by:
I am creating an application that is quite complex. There will be several dozen objects, most of which have delegates defined. At runtime, there will be several hundred instances of some objects...
2
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
3
by: shuisheng | last post by:
Dear All, Assume I have two classes: material and shape, as follows class Material { double density; // material attribute, may have more vector<Shape*pShape; // shape objects assocaited...
1
by: Jeff | last post by:
I need to place a "Previous Page" link on every page within my site and a simple javascript:history.back() will not work because I need it to capture the state of the page when I left it. For...
1
by: Jonathan Wood | last post by:
In the past, using either C++ or VB (classic), I routinely stored records of data as an array of structures, and then simply read and wrote them to and from a file using basic file operations. ...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.