carlosp wrote:
> Hello, just starting to work on pointers. Nice, but there is a very
> antiintuitive thing that bothers me...
>
> I have a collection of objects (with no meaningful "==" operator on
> them). I am using pointers to move them, sort them, etc. I want to
> evaluate if two pointers point to the same object. However, using
>
> ptr1 == ptr2
>
> yields true even if they are different as reported in std!!! Here is a
> piece of my code, and the output.
>
> if(test(i)==test(i+i)){
> std::cerr << "pointer i "<< test(i) << ", pointer i+1 "<<
> test(i+1) << "\n";
> abort();
> }
>
>
> with the result corresponding to that part of the program
>
> pointer i 0x102280, pointer i+1 0x1022c8
> Abort trap
>
>
> Whats going on here?? Please illuminate me!
I would avoid evaluating test() twice. Save the values in two variables, then
use those two variables both for the if() and for the output statements. This
way you are reasonably sure that the values used in the test and the values
which are printed are identical. Even better would be to store the result of the
"==" in a third variable.
Said that, can we see the code of test()?
Ciao,
--
Roberto Divia` Love at first sight is one of the greatest
Dep

H Bat:53 Mailbox:C02110 labour-saving devices the world has ever seen
Route de Meyrin 385 ---------------------------------------------
Case Postale Phone: +41-22-767-4994
CH-1211 Geneve 23 CERN Fax: +41-22-767-9585
Switzerland E-Mail: