Separate names with a comma.
Discussion in 'Mac Programming' started by Soulstorm, Mar 27, 2005.
When I write this code, all I get is errors concerning the declaration of "count" variable. I get those errors from both DevC++ and XCode...
I saw this code in the book named "C++ from the ground up, third edition by herbert schildt".
What is wrong with this code?
Edit: Forget it... I'll look better...
How about wrapping a code tag around your code... lets see the indents...
Edit2: It's been a while, and I don't think this is the error, but is it wise to have a local and a global variable with the same name...?
Edit3: On second thought, change the local variables name, and see if it will compile and run...
It's something to do with count being used already in the std namespace. If you replace all instances of count with count1 then g++ can compile it fine and it runs as expected.
Edit: note that using the same name for a local and global variable is fine. This looks like code designed to show what happens when you do that and how the scope rules work.
indeed! thanks, man!
One question though. Was this "count" thing added into the c++ after year 2003? how can it be that the book writes the code using "count", since it is already used by the c++ language?
To be honest I've no idea. I don't really use C++. Neither does your code apart from using C++ style output. I am just used to reading compiler errors! It is possible that the author of the book was using an old toolchain so did not see the errors.
It appears to be a clash with something in the STL which is not nearly as standard as the S in the acronym might have you believe! I'd move on and not worry about it. The code still teaches you the lesson it's meant to and you are unlikely to encounter this in real life.
Is DevC++ based on gcc (XCode is)? The clash may only occur in gcc implementations.