In python it is very easy to store the instances of a class. Later it
is also easy to retrieve them back, and hence retrieving the data
associated with them. Imaging that a program manage proteins data in a
laboratory. It prompt the user for the name of the protein (lets say
protein_1). An instance of class PROTEINS will be initiated with the
name protien_1. Then it will prompt the user for the data that should
be associated with the instance protein_1. The name of the instance,
and the associated data are then stored on the disc. In time the
number of proteins (instances) stored on disc will grow. If another
user wants to retrieve information on a certain protein, he just types
the name of the protein (instance name) and the data associated with
it will be retrieved.
doing this with python is easy since it is possible to instanciate
with a string like:
myName = "Frank" // Creates string variabl.
myClass myName // Instantiate with the string variable as instance
name.
and then store the instance name in a list.
However, I'm getting hard time with reproducing this with c++. So, any
help is appreciated.
Thanks in advance.
You need to get a good book on C++ and read the section on C++
streams. There is no automated way to save/restore objects in
C++, you have to write almost everything yourself.
Victor
--
Please remove capital A's from my address when replying by mail
C++ is not at all like Python, so your Python experience is not going to be
of much help. Basically, there is no way of doing what you want directly
using C++, as in C++ all types must be known at compile-time. You will need
to implement an object persistence layer yourself, which is not a trivial
undertaking, or use an OO database such as ObjectStore from www.odi.com.
NeilB
In C++ using std file io you are able to write a class in binary to a file
and read the file in binary and cast it to your object. I have an example
of using this in a console level editor program I created for a alteration
of pong i also created. The source file is here
(http://www.deadprogrammerssociety.com/private_dps/v1.8fiona/level_editor/level_editor.cpp)
this is another, simpler example.
//*********************************
char fileName[80];
MyClass MyClassObject(8);
cout << "Please enter the file name: ";
cin >> fileName;
ofstream fout(fileName,ios::binary);
fout.write((char*) &MyClassObject, sizeof MyClassObject);
fout.close();
// this io statement is just to show how the data changes when you read the
// object from the file
cout << "Data: " << MyClassObject.data << endl;
MyClassObject.data = 10;
cout << "Data: " << MyClassObject.data << endl;
ifstream fin(fileName,ios::binary);
fin.read((char*) &MyClassObject, sizeof MyClassObject);
fin.close();
cout << "Data: " << MyClassObject.data << endl;
--
----------------------------------------------------------------------
Azam
----------------------------------------------------------------------
This only works for PODs with no pointers. If your data object holds a
pointer you have no guarantee that the value you wrote out will be a
reasonable pointer when it's read back in. If your data object has
virtual functions most compilers use a vtable, whose address is held in
a pointer in the object. Again, no guarantee that when you read it back
in it's the right address.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
[SNIP]
>I've bought a c++ book (Learn c++ in 21 days) to learn the
>basics, but this book is really disappointing and from the title I can
>guess now that the author has a strange perception for time, and from
>the way he approach teaching I can tell that he is either never been
>in school (which not really probable) or he is considering himself as
>the standard to estimate how quick people can learn, or it might be my
>lazy brains which can't learn c++ within 21 days. I'd like to know
>what the opinion of other newbies on this book.
I liked it.
If you read the preface or introduction, I believe he makes it clear
that "21 days" is actually a metaphor, and that to learn the lessons
thoroughly you need to spend some more time and probably repeat some
of the lessons. The quizzes at the end of each "day" are sometimes
tricky, and in the edition I had (I gave it away to a student of mine
some time ago) there were several typo's in the quiz text which caused
some confusion. But on the whole, I thought it was a good beginner's
book.
You'll probably need more than one book until you really understand
everything.
Bob Hairgrove
rhairgro...@Pleasebigfoot.com
I have to agree with the above. The first C++ book I read was "Learn C++ in
21 days". I foudn that this book was an easy read and as stated above
Jesse Liberty takes great care to express that the 21 days are 21 days of
reading the lessons 1 time and 344 days of reviewing and practice. He
states that it shoudl atke the average person 1 year to get a firm
understanding of C++, However I feel to get a firm understanding of the
material you need to read a couple of book to get more authors information.
Of the books I have read I suggest reading "CPP in 21 days" as a starting
book. It is an easy read and covers alot of material. After the
completion of this book I suggest reading Bjarne Stroustrup's book "The C++
programming language", This book however is a much harder and more
complicated read than the other. However I feel this book covers alot of
ground and is as abotu as complete as you can get.
--
____________________________________________________
Adam aka "Azam" Maziarz
http://www.deadprogrammerssociety.com
az...@cox.net
Yes, I'm aware of this. You know, the problem is that the introduction
to a new topic is ok, but when he advance further he makes big jumps.
For example, when he covers classes he gives few trivial examples and
suddenly jumps to nested classes. Furthermore, most of the examples
are either a class of "CATS" or "RECTANGLES". Well, it happened that I
hate both;-). He did'nt even cover hash_tables, and does not make the
distinction between what is really required to know/learn at this
stage of learning and which one is 'cosmetic'.
> You'll probably need more than one book until you really understand
> everything.
sure, I just bought c++ primer.
chears.
Bjarne's book also has the advantage of not being riddled with
literally hundreds of serious errors, and being written by someone who
both understands the language and knows how to teach it properly. But
it is not intended for absolute beginners to programming, as I'm sure
he would agree.
--
Steve Heller
http://www.steveheller.com
Author of "Learning to Program in C++", "Who's Afraid of C++?", "Who's Afraid of More C++?",
"Optimizing C++", and other books
Free online versions of "Who's Afraid of C++?" and "Optimizing C++" are now available
at http://www.steveheller.com/whos and http://www.steveheller.com/opt
>He did'nt even cover hash_tables, and does not make the
>distinction between what is really required to know/learn at this
>stage of learning and which one is 'cosmetic'.
Hashing has nothing to do with the language of C++ ... it's an
algorithm.
Bob Hairgrove
rhairgro...@Pleasebigfoot.com
I'm sorry to see he is still at it. For the record, my book does not have
hundreds of errors, and every known error is carefully documented on my web
site (where I also provide extensive personal support to my readers. The
errata for the fourth edition has about half a dozen. With over 500,000
copies of my various books in print, I have worked hard to record every
error in every edition, and to ensure that each edition is better than the
last.
As for whether I understand the language and know how to teach it, I can not
be the judge. I've received both praise and criticism, I try to learn from
both. I can tell you that Barnes and Noble's editors wrote, "We're convinced
[Jesse Liberty ] could teach programming to chimpanzees..." Of course, not
all the reviews are good, and each reader must judge for himself.
I can only ask Mr. Heller, as I have so many times in the past, to please
constrain himself to discussing why his books are good, rather than running
down the competition. I'm sure there is plenty for him to be proud of, there
is no need for him to talk about my books at all.
Thank you.
--
Jesse Liberty
Liberty Associates, Inc.
http://www.LibertyAssociates.com
"Steve Heller" <st...@steveheller.com> wrote in message
news:4emqducjr88afebhe...@4ax.com...
> Azam <az...@cox.net> wrote:
>
> >Bob Hairgrove wrote:
> >
> >> On 11 May 2002 02:31:57 -0700, husam...@hotmail.com (Husam) wrote:
> >>
> >> I liked it.
> >>
> >> If you read the preface or introduction, I believe he makes it clear
> >> that "21 days" is actually a metaphor, ...
> >
> >I have to agree with the above. ...
>
> Bjarne's book also has the advantage of not being riddled with
> literally hundreds of serious errors, and being written by someone who
> both understands the language and knows how to teach it properly.> --
>Some years back I asked Steve Heller to stop attacking my books in public.
>As the author of competing works, I think it is shameful that he slanders
>the work of other authors
I haven't slandered anyone's books.
>I'm sorry to see he is still at it. For the record, my book does not have
>hundreds of errors, and every known error is carefully documented on my web
>site (where I also provide extensive personal support to my readers. The
>errata for the fourth edition has about half a dozen. With over 500,000
>copies of my various books in print, I have worked hard to record every
>error in every edition, and to ensure that each edition is better than the
>last.
Did I refer to your book in the message you refer to? If so, where?
What I said was that Bjarne's book has the advantage of not having
hundreds of errors. Any inference about your book is your
responsibility, not mine.
>As for whether I understand the language and know how to teach it, I can not
>be the judge. I've received both praise and criticism, I try to learn from
>both. I can tell you that Barnes and Noble's editors wrote, "We're convinced
>[Jesse Liberty ] could teach programming to chimpanzees..." Of course, not
>all the reviews are good, and each reader must judge for himself.
If I run across any chimpanzees who want to learn C++, I'll keep
that in mind.
>I can only ask Mr. Heller, as I have so many times in the past, to please
>constrain himself to discussing why his books are good, rather than running
>down the competition. I'm sure there is plenty for him to be proud of, there
>is no need for him to talk about my books at all.
In fact, my comments did not mention your book at all. I'm afraid
your insecurity is showing.
>"Jesse Liberty" <jlib...@libertyassociates.com> wrote:
>
>>Some years back I asked Steve Heller to stop attacking my books in public.
>>As the author of competing works, I think it is shameful that he slanders
>>the work of other authors
>
> I haven't slandered anyone's books.
Not explicitly, you didn't. However, since most of the quoted material
was about Jesse Liberty's book, it's extremely difficult NOT to assume
that you were talking about that one. The insinuation was certainly
there.
Bob Hairgrove
rhairgro...@Pleasebigfoot.com
People can make whatever assumptions they like. However, let's
suppose someone were to make negative statements in a post that
discussed one of my books, without mentioning my book specifically,
and those statements were not true of my book. In such a case, my
response would simply be to say "It's a good thing those statements
aren't true of my book", not "My book is being slandered".
But in the future, I won't even state my own opinion of Mr.
Liberty'se books at all, but will simply quote from readers' comments
on Amazon. Then no one can accuse me of slander even by implication,
as I am just reporting what someone else has written.
Liability for libel or slander arises from publishing a statement that
is injurious, regardless of the source.
This is silly. Anyone reading the message thread can see what you wrote.
There is no need for you to comment on my books at all, just as there is no
need for me to comment on your books or quote reviews or in any way stir up
trouble for you. I have no doubt you can find reviews that slam my book just
as you can find reviews that praise it. I have 1 star and 5 star reviews.
With over 500,000 readers, my books receive a wide range of responses; I try
to learn from all the reviews, so that I can continue to improve my books.
You are a competitor, why don't you have the grace to just talk about your
own books and leave those of other authors alone?
-j
--
Jesse Liberty
Liberty Associates, Inc.
.NET Training & Programming
http://www.LibertyAssociates.com
"Steve Heller" <st...@steveheller.com> wrote in message
news:h7tceu8ovaq0gsfri...@4ax.com...
> > But in the future, I won't even state my own opinion of Mr.
> > Liberty'se books at all, but will simply quote from readers' comments
> > on Amazon. Then no one can accuse me of slander even by implication,
> > as I am just reporting what someone else has written.
> >
>
> Liability for libel or slander arises from publishing a statement that
> is injurious, regardless of the source.
Um.... We have a new country over here, you know. Since 1780 or
thereabouts. :-)
You know, before this exchange (and others) on this newsgroup I had no
opinion whatsoever of Steve Heller. I hadn't read any of his books,
nor had I seen reviews of his books. My own list of C++ books is
pretty small (The C++ Programming Lang. 2nd, and then 3rd edition,
Scott Meyers' Effective/More Effective C++, Herb Sutter's
Exceptional/More Exceptional C++, Josuttis' The C++ Standard Library,
and that's about it).
Now, I have no intention of reading or recommending Heller's books.
Funny how that works out.
--
Mark Ping
ema...@soda.CSUA.Berkeley.EDU
What's your point?
Or some other solution(s) like (just FYI/"food for thought";
it meant to be used/work with all kinds of "files" -- POSIX/
VSAM, DBMS/"like sql", WebSphere-MQ, etc.):
<< That's IBM patent appl. (US:13.08.2001/09/928881,
EU:28.09.2000/... etc.) >>
http://www.terekhov.de/OO-Persistence/DE9-2000-0074-ep-9-2000.pdf
http://www.terekhov.de/OO-Persistence/ep-d-9-2000.pdf
("Method and System for Persistently Storing Objects
in an Object Oriented Environment")
Basically the idea is to have *fast*/incrementally updateable
persistence layer/image just using simple PTR/ADDRESS translations
for object refs/handlers and object "pieces"). It works here:
http://www.ibm.com/servers/eserver/zseries/software/sa/pdf/ingpie02.pdf
(search on "Recovery Concept for the Automation Manager")
> But, the problem with this is that I have to dive
> into data base techniques in order to do what I want to do.
I'd recommend studying data structures and algorithms: b*-trees,
etc. (the "lists" referenced in the appl. are actually b*-trees).
regards,
alexander.
>Steve Heller wrote:
>>
>> But in the future, I won't even state my own opinion of Mr.
>> Liberty'se books at all, but will simply quote from readers' comments
>> on Amazon. Then no one can accuse me of slander even by implication,
>> as I am just reporting what someone else has written.
>>
>
>Liability for libel or slander arises from publishing a statement that
>is injurious, regardless of the source.
Do you have a reference for that? That runs against my understanding
of the law.
>Steve,
>
>This is silly. Anyone reading the message thread can see what you wrote.
Yes, they certainly can. And if they do, they will see that I made
no reference to your book(s) at all.
>There is no need for you to comment on my books at all, just as there is no
>need for me to comment on your books or quote reviews or in any way stir up
>trouble for you. I have no doubt you can find reviews that slam my book just
>as you can find reviews that praise it. I have 1 star and 5 star reviews.
>With over 500,000 readers, my books receive a wide range of responses; I try
>to learn from all the reviews, so that I can continue to improve my books.
That's an admirable goal. I suggest you spend your time doing that
rather than trying to find ways to attack me for making comments that
do not mention your book.
>You are a competitor, why don't you have the grace to just talk about your
>own books and leave those of other authors alone?
I don't consider your books competition to mine.
Let me see if I understand this. You haven't read or recommended any
of my books before, and after reading this thread, you aren't going to
read or recommend them. What an effect this thread must have had on
you!
Can I point out that whatever one believes is on-topic here, bitching about
another persons books is definitely not. Could you and Mr Liberty (and
anyone else who wants to join in) please take this to email.
NeilB
> "Jesse Liberty" <jlib...@libertyassociates.com> wrote:
>
> >Steve,
> >
> >This is silly. Anyone reading the message thread can see what you wrote.
>
> Yes, they certainly can. And if they do, they will see that I made
> no reference to your book(s) at all.
No, but it was clear, to me at least, that with "also has the
advantage of not being riddled with literally hundreds of serious
errors" when you referred to Bjarne's book, that you meant that the
book that was under discussion (the "21 days" book) had these errors.
If I say "I read book A" and someone else says "I prefer book B" and
you say "yeah indeed, and B doesn't have hundreds of errors either",
it is clear you refer to book A.
So in that context it was not necessary to name the book under
discussion explicitly. It was clearly implied in what you said, IMO.
Where did you say you got your law degree? It's black letter law.
>Steve Heller wrote:
>>
>> Pete Becker <peteb...@acm.org> wrote:
>>
>> >Steve Heller wrote:
>> >>
>> >> But in the future, I won't even state my own opinion of Mr.
>> >> Liberty'se books at all, but will simply quote from readers' comments
>> >> on Amazon. Then no one can accuse me of slander even by implication,
>> >> as I am just reporting what someone else has written.
>> >>
>> >
>> >Liability for libel or slander arises from publishing a statement that
>> >is injurious, regardless of the source.
>>
>> Do you have a reference for that? That runs against my understanding
>> of the law.
>>
>
>Where did you say you got your law degree? It's black letter law.
Plonk.
>On Sat, 18 May 2002 20:49:08 GMT, Steve Heller <st...@steveheller.com>
>wrote:
>
>> "Jesse Liberty" <jlib...@libertyassociates.com> wrote:
>>
>> >Steve,
>> >
>> >This is silly. Anyone reading the message thread can see what you wrote.
>>
>> Yes, they certainly can. And if they do, they will see that I made
>> no reference to your book(s) at all.
>
>No, but it was clear, to me at least, that with "also has the
>advantage of not being riddled with literally hundreds of serious
>errors" when you referred to Bjarne's book, that you meant that the
>book that was under discussion (the "21 days" book) had these errors.
How nice for you.
>If I say "I read book A" and someone else says "I prefer book B" and
>you say "yeah indeed, and B doesn't have hundreds of errors either",
>it is clear you refer to book A.
It may be clear to you, but I didn't say it.
>So in that context it was not necessary to name the book under
>discussion explicitly. It was clearly implied in what you said, IMO.
That is indeed your opinion.
>Can I point out that whatever one believes is on-topic here, bitching about
>another persons books is definitely not. Could you and Mr Liberty (and
>anyone else who wants to join in) please take this to email.
I've made my last post on this topic. Sorry to have annoyed you.
> It may be clear to you, but I didn't say it.
Indeed, you cleverly avoided that.
> >So in that context it was not necessary to name the book under
> >discussion explicitly. It was clearly implied in what you said, IMO.
>
> That is indeed your opinion.
And I'm pretty sure that it is not just mine.
Well, why should I care anyway? I am not writing and selling any
books, or making remarks about other people's books. I don't have to
make a good impression here.
Against stupidity the very gods
Themselves contend in vain
-- Schiller
>On Sat, 18 May 2002 23:08:05 GMT, Steve Heller <st...@steveheller.com>
>wrote:
>
>> It may be clear to you, but I didn't say it.
>
>Indeed, you cleverly avoided that.
Thank you.
>> >So in that context it was not necessary to name the book under
>> >discussion explicitly. It was clearly implied in what you said, IMO.
>>
>> That is indeed your opinion.
>
>And I'm pretty sure that it is not just mine.
>
>Well, why should I care anyway? I am not writing and selling any
>books, or making remarks about other people's books. I don't have to
>make a good impression here.
How nice for you.