469,903 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Creating inherited class with set base class

I'm doing recomposition of objects from binary streams, and the best
way for me to write them out is to write base class data first, forward
to inherited classes, pointer class values, etc.

Now, when recomposing these objects, I first read the base class data,
and can create a base object.

When I find the inherited class marker, can I call have the inherited
class use the prior base object to population the inherited class's
base object?
If so, would this have to be done in the constructor, or could I do
this using an initialization list?

Thanks,
Josh McFarlane

Aug 18 '05 #1
2 2010
Josh Mcfarlane wrote:
I'm doing recomposition of objects from binary streams, and the best
way for me to write them out is to write base class data first, forward
to inherited classes, pointer class values, etc.

Now, when recomposing these objects, I first read the base class data,
and can create a base object.

When I find the inherited class marker, can I call have the inherited
class use the prior base object to population the inherited class's
base object?
Uh...
If so, would this have to be done in the constructor, or could I do
this using an initialization list?


You should be able to define a constructor that takes an instance of the
base class and the stream (suspended at some position), you then can do

class derived_N : public base {
...

derived_N(base const & b, mystream & str) :
base(b) {
... // process 'str' here
}
};

Is that what you're asking?

V
Aug 18 '05 #2

Victor Bazarov wrote:
You should be able to define a constructor that takes an instance of the
base class and the stream (suspended at some position), you then can do

class derived_N : public base {
...

derived_N(base const & b, mystream & str) :
base(b) {
... // process 'str' here
}
};

Is that what you're asking?


Ya, that's exactly what I wanted to know. May seme simple, but I didn't
know exactly how to place it. Just didn't want to have to re-read
through the stream and start over to reinitialize the derived base.

Thanks!
Josh

Aug 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Chad Miller | last post: by
3 posts views Thread by Jeff User | last post: by
3 posts views Thread by Wayne Brantley | last post: by
19 posts views Thread by jan.loucka | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.