Hello.I'm writing a program who uses objects and inheritance.I know that soring them in and retriving from files is going to be very hard.(serialize, digitize and back again)
again, saving in relational databases is not gonna be easy, as this reqires digitization too.
what is the solution to my problem?
please note that I have fields in my classes that are themselves objects(strings) and so it's gonna be such a hard job storing them.I need quite a bit of advice!
It's not really hard. You just need to serialize each class member. For types like int, bool etc. you can write the value directly to the stream. For class instance members call their serialize method. Containers (including string) don't have one, so store the number of elements first, then serialize each member. For strings an alternate method is to null-terminate it and omit the length.
Serializing to a SQL database is a bit trickier (unless you just store a binary blob, then there is no difference). You can have your serialize methods build an insert SQL statement. Since calls to serialize of class members might create an insert statement of their own, they should return their primary key for the caller to use.
Anyway, I'd stick to saving to simple binary files before tackling this.
Another option is to use XML files - there are various advantages and disadvantages to that.
You also should have a look at Boost.Serialization.
sorry, but your answers are too vague for me.Do I have to use boost anyway?
Does boost comply with Ubuntu linux?
sorry athar, but were are my serialization methods?
I guess SQL Database manager is too expensive for me-so ignore it!
I know nothing about XML
My problem is how to serialize objects which are part of inheritance tree of the program and deserialize them.I have no experiments with serializing objects
You need to go to www.boost.org, download the latest version of boost (if you don't already have it installed;
yes, boost is cross-platform), and read the documentation on the boost.serialization library. It will give you
examples of how to serialize and deserialize objects, including polymorphic objects. To do this will require you
to write serialize methods for each of your types that you want to be able to serialize and deserialize.