Creating inherited class with set base class

J

Josh Mcfarlane

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
 
V

Victor Bazarov

Josh said:
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
 
J

Josh Mcfarlane

Victor said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top