Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > (help) Runtime error in ifstream/ios class

Reply
Thread Tools

(help) Runtime error in ifstream/ios class

 
 
Massimo Soricetti
Guest
Posts: n/a
 
      01-13-2006
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
 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      01-13-2006
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-lit....html#faq-24.2
http://www.parashift.com/c++-faq-lit....html#faq-24.3

Cheers! --M

 
Reply With Quote
 
 
 
 
Massimo Soricetti
Guest
Posts: n/a
 
      01-14-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
How to find at Runtime, if Created class object is instance of given class declaration Ami C++ 3 02-27-2006 04:59 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Comparing a jar'd class to the runtime class James D Carroll Java 8 06-27-2004 06:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57