12-11-2003, 06:02 AM | #1 (permalink) | |
/nɑndəsˈkrɪpt/
Location: LV-426
|
C++ ifstream pointer question
Here's the code, i just want to count the lines of a file. I get a bunch of "invalid simple type name destructor" errors..
It makes a pointer to an input stream to the file specified by the command line parameter. Then it passes the pointer to countlines() to try to count the lines. anyone know why it doesn't work? Quote:
__________________
Who is John Galt? |
|
12-11-2003, 08:06 AM | #3 (permalink) | |
I am Winter Born
Location: Alexandria, VA
|
Quote:
__________________
Eat antimatter, Posleen-boy! Last edited by Pragma; 12-11-2003 at 08:12 AM.. |
|
12-11-2003, 08:11 AM | #4 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
Well, you can't do "delete null;", as it's not dynamic memory.
Other than that, why are you using an ifstream pointer instead of just an ifstream object? Furthermore, C++ really doesn't like it when you redefine constants for it - such as NULL.
__________________
Eat antimatter, Posleen-boy! |
12-12-2003, 06:00 AM | #8 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
True, you can redefine constants, but most compilers will give you warnings, if not errors, if you don't #undef before you #define.
Either way, I've seen very few cases (and this not being one of them) were actually redefining NULL is warranted.
__________________
Eat antimatter, Posleen-boy! |
12-12-2003, 05:57 PM | #9 (permalink) |
Junkie
Location: North Hollywood
|
You should never get an error redefining a #define, a typedef yes, if you do the compilers broken.
some compilers will generate an error using #undef on something that was never #define'd so you should always guard it. Unfortunately theres no easy way of telling the difference between a typedef and a #define. You might get an error on the use of the redefined #define, but thats not because of the redefine itself. I like to redefine NULL on projects i know are going crossplatform, then i know what its going to be, theres only a few rare systems where NULL isn't 0, but i've seen enough uses of (void*) 0 to do it, plus it doesn't hurt anything. using null as an arrayname though is asking for trouble |
12-12-2003, 06:22 PM | #10 (permalink) |
Psycho
Location: London...no longer a student
|
arghhhh i forgot how much i hated c++ .... i'm so glad i learnt java first....wrong way round i know...but its just so much easier! pointers may be helpful, but understanding them takes a long time!
__________________
"Never underestimate a dumb question"-- Brandon Boyd |
12-12-2003, 06:32 PM | #11 (permalink) |
Junkie
Location: North Hollywood
|
yep a lot of people probably can get by without pointers, but the things i miss the most in java are pointers, enums and #defines (though i do use #defines and run it through a preprocessor )
Oh and a stable development environment, and speed .. ok'll i'll stop |
12-14-2003, 05:57 AM | #14 (permalink) |
Quadrature Amplitude Modulator
Location: Denver
|
LOL, yeah, brainfuck is a great language for that purpose.
Next, try to figure out assembly (any architecture, preferably x86 for maximum pain) without understanding pointers.
__________________
"There are finer fish in the sea than have ever been caught." -- Irish proverb |
Tags |
ifstream, pointer, question |
|
|