Use Streams to Initialize Objects

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Use Streams to Initialize Objects

      A little leftover from the 1st ed.?

      Use Streams to Initialize Objects
      Any persistent object in your game should implement an overloaded constructor that takes a stream object as a parameter ... Here's an example:


      Then the example shows a normal constructor( no params ) and an Initialize( InputStream &stream ) function..

      The 'should implement constructor which takes stream obj as param' text is a bit odd, considering a few lines down you write:

      If you read the 1st ed. of this book, perhaps you remember that this section suggested you use input streams in the constructor of an object, like this <example>, Boy, that was a horrible idea..etc..



      Or am I just confused? :)
    • RE: Use Streams to Initialize Objects

      Yup. Good catch.

      Stream constructors are a bad idea, because there's no good way to fail out of a constructor. Having objects have an Init(...) method that takes a stream for a parameter is really useful.

      You could init something from a save game file on disk or even init it through a network. Very cool.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: Use Streams to Initialize Objects

      I finally got off my butt and fixed the text for GCC 3rd edition.
      Mr.Mike
      Author, Programmer, Brewer, Patriot