Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

17
  • 21
    @Jonathan: Why would C++ know how you want to compare your structs for equality? And if you want the simple way, there's always memcmp so long your structs don't contain pointer. Commented Apr 21, 2011 at 6:59
  • 18
    @Xeo: memcmp fails with non-POD members (like std::string) and padded structures. Commented Apr 21, 2011 at 8:07
  • 17
    @Jonathan The "modern" languages I know do provide a == operator---with a semantic that is almost never what is wanted. (And they don't provide a means of overriding it, so you end up having to use a member function). The "modern" languages I know also don't provide value semantics, so you're forced to use pointers, even when they aren't appropriate. Commented Apr 21, 2011 at 8:48
  • 4
    @Jonathan Cases definitely do vary, even within a given program. For entity objects, the solution provided by Java works very well (and of course, you can do exactly the same thing in C++---it's even idiomatic C++ for entity objects). The question is what to do about value objects. C++ provides a default operator= (even if it often does the wrong thing), for reasons of C compatibility. C compatibility doesn't require an operator==, however. Globally, I prefer what C++ does to what Java does. (I don't know C#, so maybe that's better.) Commented Apr 25, 2011 at 14:56
  • 17
    At least it should be possible to = default it! Commented Feb 16, 2016 at 16:12