(help) Runtime error in ifstream/ios class

Discussion in 'C++' started by Massimo Soricetti, Jan 13, 2006.

  1. 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(void);
    DWORD GetDword(bool);
    WORD GetWord(bool);
    BYTE GetByte(void);
    int readPascalString(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
    Massimo Soricetti, Jan 13, 2006
    #1
    1. Advertising

  2. Massimo Soricetti

    mlimber Guest

    Massimo Soricetti wrote:
    > 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(void);
    > DWORD GetDword(bool);
    > WORD GetWord(bool);
    > BYTE GetByte(void);
    > int readPascalString(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


    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:

    http://www.parashift.com/c -faq-lite/private-inheritance.html#faq-24.2
    http://www.parashift.com/c -faq-lite/private-inheritance.html#faq-24.3

    Cheers! --M
    mlimber, Jan 13, 2006
    #2
    1. Advertising

  3. mlimber ha scritto:
    > 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:


    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.
    Massimo Soricetti, Jan 14, 2006
    #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. Philip Lawatsch

    ios and other

    Philip Lawatsch, Jul 13, 2003, in forum: C++
    Replies:
    1
    Views:
    402
    Mike Wahler
    Jul 13, 2003
  2. Marc Schellens
    Replies:
    8
    Views:
    2,983
    John Harrison
    Jul 15, 2003
  3. Ron Natalie
    Replies:
    2
    Views:
    1,552
    WahJava
    Mar 2, 2005
  4. Kira Yamato

    Help needed for STL ifstream class

    Kira Yamato, Oct 6, 2007, in forum: C++
    Replies:
    11
    Views:
    729
    James Kanze
    Oct 6, 2007
  5. Replies:
    1
    Views:
    402
Loading...

Share This Page