Checking equality of two pointer addresses is not working

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
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.
Thank you :)! I'm very bad with pointers :(.
Topic archived. No new replies allowed.