Creating inherited class with set base class

Discussion in 'C++' started by Josh Mcfarlane, Aug 18, 2005.

  1. 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
    Josh Mcfarlane, Aug 18, 2005
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Aug 18, 2005
    #2
    1. Advertising

  3. 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
    Josh Mcfarlane, Aug 18, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Softari
    Replies:
    1
    Views:
    429
    John Harrison
    Jul 14, 2004
  2. Softari
    Replies:
    1
    Views:
    379
    red floyd
    Jul 14, 2004
  3. Alicia
    Replies:
    3
    Views:
    944
    jjr2004a
    Nov 24, 2004
  4. gabe
    Replies:
    1
    Views:
    432
    Mark Rae
    Mar 21, 2007
  5. 7stud --
    Replies:
    11
    Views:
    401
    7stud --
    Nov 9, 2007
Loading...

Share This Page