Re: serialization, size errors... or something else.

  • From: "qubit" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 30 Jun 2010 18:11:44 -0500

Ok, here's the situation --
class C : public A, public B {};
B has a virtual function -- in fact, it has virtuals. Therefore C has a 
virtual pointer in it.
C* cp = new C; // ok
If you say a* ap = cp;
all is fine.  But if you say
B* bp = cp;
this may not work in current compilers, I don't know -- but since B is 
positioned sizeof(A) bytes (supposedly) from the beginning of c, the 
compiler adds that many bytes to the value of cp and assigns the new value 
to bp.
You can probably imagine ways to mix things up.

Anyway, your strategy, from what you say, does not call fwrite on class 
types, correct? or does it?
And if it does, what do you want it to do?
Your strategy should work as long as fwrite is only called on types that are 
not pointers to classes.  If T is a class type, then you don't really know 
if the object T& t is a derived object or a plain T object.  If it is 
derived and you don't know it, you will be truncating data.
I hope this makes some kind of sense.
Sounds like your system is a great bit of engineering--hope you get it 
working right.
--le



----- Original Message ----- 
From: "Tyler Littlefield" <tyler@xxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, June 30, 2010 5:41 PM
Subject: Re: serialization, size errors... or something else.


How else should fwrite be used? I'm not sure what your getting at with the 
pointers, but I'm not passing pointers round besides the serialize object, 
which just writes the class members.__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: