Topic: incrementing problems


Author: JG@opticon.demon.co.uk (John Goodwin)
Date: 1998/03/07
Raw View
On 25 Feb 1998 16:42:38 GMT, "Dave Robinson" <dave@globalnet.co.uk>
wrote:

>I know this might be a stupid suggestion, but your indentation would suggest
>that you might have simply missed out the block delimiters... i.e.
>
>void classname::addInteger(int intadd){
>        if (!hasInteger(intadd)) {
>                array[index]=intadd;
>                index++;
>        }
>}

But that would not account for the double increment.

I tried this under VC4.2, and it worked as expected.

snip
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Dave Robinson" <dave@globalnet.co.uk>
Date: 1998/02/25
Raw View
I know this might be a stupid suggestion, but your indentation would suggest
that you might have simply missed out the block delimiters... i.e.

void classname::addInteger(int intadd){
        if (!hasInteger(intadd)) {
                array[index]=intadd;
                index++;
        }
}

Dave Robinson,
Malvern, UK

PUFDAD100 wrote in message
<19980220004800.TAA25748@ladder02.news.aol.com>...
>I have a problem involving incrementing. Here's an example:
>
>void classname::addInteger(int intadd){
>        if (!hasInteger(intadd))
>                array[index]=intadd;
>                index++;
>}
>
>//the hasInteger() function checks if intadd is already in the array
>//if it is it returns true else false. array[] is an integer array in
>//classname. index is also data of type integer in classname.
>
>When I run this function, index is increment twice. Debugging it, I found
out
>that right after "array[index]=intadd;" index is incremented and then of
course
>it is incremented again after "index++;". What is the problem? I've tried 2
>different compilers(Symantec C++ 7.2 and Borland C++ 4.02) and they both
did
>the same thing. If anyone knows the answer to this please email me.
>
>Thanks
>Leo


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: pufdad100@aol.com (PUFDAD100)
Date: 1998/02/21
Raw View
I have a problem involving incrementing. Here's an example:

void classname::addInteger(int intadd){
        if (!hasInteger(intadd))
                array[index]=intadd;
                index++;
}

//the hasInteger() function checks if intadd is already in the array
//if it is it returns true else false. array[] is an integer array in
//classname. index is also data of type integer in classname.

When I run this function, index is increment twice. Debugging it, I found out
that right after "array[index]=intadd;" index is incremented and then of course
it is incremented again after "index++;". What is the problem? I've tried 2
different compilers(Symantec C++ 7.2 and Borland C++ 4.02) and they both did
the same thing. If anyone knows the answer to this please email me.

Thanks
Leo
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]