By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,900 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,900 IT Pros & Developers. It's quick & easy.

Creating inherited class with set base class

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

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.