Non-standard compiler??

I am working out of a book that claims that their examples comply to standard C++. There is a particular line of code in an example in their book that is generating errors for my compiler:

1
2
3
4
if ((char ch = inBuf[ix]) == '.')
{
    /*various code here*/
}


It generates the error:
error C2146: syntax error : missing ')' before identifier 'ch'

The book does say that using 'ch' here in this case is unnecessary but it was used to illustrate a point.

I am using Visual C++ 6.0.
Any insight would be appreciated, thanks.
Not sure if it's because VC6 is too old or not. Have you tried with another compiler? GCC is up to 4.7.2 and is pretty current with C++11 standard.
which book is that, because I believe that statement is illegal in C++.
This is not allowed. You will have to declare ch outside the if statement.
1
2
3
4
5
char ch;
if ((ch = inBuf[ix]) == '.')
{
    /*various code here*/
}
Thanks for the responses, the book is C++ primer 3rd edition.
Third edition is from early 1998, when the first revision of the standard was just on its way to publication. Even the coauthors of C++ can make mistakes. Get the fifth edition, from 2012.
Topic archived. No new replies allowed.