C
carlosp
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!
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!