(help) Runtime error in ifstream/ios class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Massimo Soricetti

    (help) Runtime error in ifstream/ios class

    Hello,

    I'm trying to fix this little class:
    <code>
    #include <ifstream>
    #include <iostream>
    #include <iomanip>

    using namespace std;

    class iExeStream: ifstream
    {
    public:
    int GetDOSheader(vo id);
    DWORD GetDword(bool);
    WORD GetWord(bool);
    BYTE GetByte(void);
    int readPascalStrin g(char *);
    };
    </code>

    I'm using BC++Builder 6.
    It compiles correctly, but when I launch the program it dies with a
    runtime error before even show the first program screen. I know ths
    behaviour is sometime caused by faults in static objects ctors, who are
    executed before the program starts, but no one of the iExeStream objects
    I use is static.

    With BCB6 debugger, after clicking OK on the error window it opens the
    "ios.h" header file??? o_O
  • mlimber

    #2
    Re: (help) Runtime error in ifstream/ios class

    Massimo Soricetti wrote:[color=blue]
    > Hello,
    >
    > I'm trying to fix this little class:
    > <code>
    > #include <ifstream>
    > #include <iostream>
    > #include <iomanip>
    >
    > using namespace std;
    >
    > class iExeStream: ifstream
    > {
    > public:
    > int GetDOSheader(vo id);
    > DWORD GetDword(bool);
    > WORD GetWord(bool);
    > BYTE GetByte(void);
    > int readPascalStrin g(char *);
    > };
    > </code>
    >
    > I'm using BC++Builder 6.
    > It compiles correctly, but when I launch the program it dies with a
    > runtime error before even show the first program screen. I know ths
    > behaviour is sometime caused by faults in static objects ctors, who are
    > executed before the program starts, but no one of the iExeStream objects
    > I use is static.
    >
    > With BCB6 debugger, after clicking OK on the error window it opens the
    > "ios.h" header file??? o_O[/color]

    There's nothing in the code you posted that seems like it would cause
    such an error, but then again, you didn't post very much. Try to reduce
    the problem to a minimal program that you could post here in its
    entirety.

    On the other hand, since classes default to private inheritance, your
    deriving iExeStream from std::ifstream is probably poor design. Simple
    composition would likely be better. See these FAQs:




    Cheers! --M

    Comment

    • Massimo Soricetti

      #3
      Re: (help) Runtime error in ifstream/ios class

      mlimber ha scritto:[color=blue]
      > There's nothing in the code you posted that seems like it would cause
      > such an error, but then again, you didn't post very much. Try to reduce
      > the problem to a minimal program that you could post here in its
      > entirety.
      >
      > On the other hand, since classes default to private inheritance, your
      > deriving iExeStream from std::ifstream is probably poor design. Simple
      > composition would likely be better. See these FAQs:[/color]

      I added a public constructor and declared "public" the inheritance of
      ifstream, now it works. The FAQ you mentioned are very interesting,
      thank you... maybe I'm going to change something in my code, however.

      Comment

      Working...