![]() |
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:
|
Well, vB removes some small parts of the code apparently in its battle against html tags, but I hope that is understandable anyway.
|
Quote:
|
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. |
You're a genius. Thanks! :)
|
for future reference code tags (use em just like quote ones) are great :)
|
its ok to redefine #define constants, you can even use #undef if you want too first.
NULL is compiler specific, so sometimes you want to override it because the compiler maker goofed it up , say using (void*)0 instead of 0 or 0L |
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. |
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 |
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!
|
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 :) |
Pointers are pretty important to figure out. Can't be a good programmer without understanding them, in my opinion.
|
If you think C/C++ pointers are bad, go learn Brainfuck. You'll petition to have the word "pointer" removed from the English language.
|
LOL, yeah, brainfuck is a great language for that purpose. :D
Next, try to figure out assembly (any architecture, preferably x86 for maximum pain) without understanding pointers. :D |
All times are GMT -8. The time now is 05:42 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project