Skip to main content
added 362 characters in body
Source Link
lucian.pantelimon
  • 3.7k
  • 4
  • 33
  • 46

Yes, it is, and yes you can compare the addresses. Only problem is if you have memory leaks and the objects don't get deleted.

Every object has a unique address. Even if you create an empty class or struct, it's size will not be zero(by language design). Be careful when passing the this reference from a constructor when working with multiple threads, as your object might not be fully constructed.

EDIT: You can use this to your advantage to discover memory leaks. Assuming you delete every object you have created by the time the program exits (like a clean-up method), just see if you have any objects left.

EDIT2: Here's a very good article on object counting in C++

Yes, it is, and yes you can compare the addresses. Only problem is if you have memory leaks and the objects don't get deleted.

Every object has a unique address. Even if you create an empty class or struct, it's size will not be zero(by language design).

Yes, it is, and yes you can compare the addresses. Only problem is if you have memory leaks and the objects don't get deleted.

Every object has a unique address. Even if you create an empty class or struct, it's size will not be zero(by language design). Be careful when passing the this reference from a constructor when working with multiple threads, as your object might not be fully constructed.

EDIT: You can use this to your advantage to discover memory leaks. Assuming you delete every object you have created by the time the program exits (like a clean-up method), just see if you have any objects left.

EDIT2: Here's a very good article on object counting in C++

Source Link
lucian.pantelimon
  • 3.7k
  • 4
  • 33
  • 46

Yes, it is, and yes you can compare the addresses. Only problem is if you have memory leaks and the objects don't get deleted.

Every object has a unique address. Even if you create an empty class or struct, it's size will not be zero(by language design).