Hi, I'm a student working on a project that uses someone's old C++ code. I know the basics of the language but I'm confused by the following piece of code:
1 2 3 4 5
if (X==\
Y)
{
Temp = X;
}
I've shortened the variables to X,Y and Temp. My confusion is about the '==\' bit. What's the '\' for? I'm tempted to say its something to do with the fact the variables are long and the equality check goes to 2 lines and its telling the compiler something about the newline, but I thought C++ just ignored whitespace.
Whether C++ likes whitespaces or not depends on where they are. In this case it isn't an issue.
I'd guess the "\" IS supposed to be a line continuation marker (as you've surmised) but I have no idea why anybody would put one after "==".
What IS an issue is the lack of closing parenthesis on the if statement.
As it stands this code will not compile which makes it bad code. As such, my suggestion would be that you DON'T stress over trying to understand the syntax.
After all, if the code doesn't compile then this means the compiler doesn't understand the syntax. There's no reason you should be able to either.
Actually, my bottom line on this is this; if a person doesn't code well enough to include a closing parenthesis on an if statement, then they probably don't really have a good reason for the use of "\" -- so trying to work out WHY it was included in this instance seems pointless.
Thanks for the advice, the poor code was my fault in trying to simplify the problem (edited and fixed), I seem to have removed too many characters!
The '\' appears after a '+=' as well and it just confused me to look at, and searching for '==\' or similar on web-sites seems pretty futile. I have compiled the code with and without the '\' and it seems to work both ways, I just didn't want to be changing its intended opperation without realising!