May 13, 2017 at 3:24pm UTC
In function isEqualTo I'm checking equality of two addresses of one object pointer, but somehow addresses don't match. Can someone solve me this problem? Thanks :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
class Test {
public :
bool isEqualTo(Test* test) {
auto address = this ;
return &address == &test;
}
};
int main() {
Test test;
Test test2;
std::cout << test.isEqualTo(&test) << std::endl;
std::cin.get();
return 0;
}
Last edited on May 13, 2017 at 3:29pm UTC
May 13, 2017 at 3:33pm UTC
Hi,
this
and test
are already pointers , but you are taking the address of them again with &
.
It worked for me when I removed the &'s on line 9.
May 13, 2017 at 3:35pm UTC
Thank you :)! I'm very bad with pointers :(.