3 ms·
What? These are overloads for smart pointers, not regular pointers, and thus require special code to get the semantics of regular pointers that are usually expe
by crazy2be 11y ago
What? These are overloads for smart pointers, not regular pointers, and thus require special code to get the semantics of regular pointers that are usually expected and desired by developers. Even the standard library unique_ptr overloads these operators (http://en.cppreference.com/w/cpp/memory/unique_ptr/operator_cmp http://en.cppreference.com/w/cpp/memory/unique_ptr/operator_...).
Of course, you could argue that smart pointers shouldn't be a thing, but I think most C++ developers would disagree given the significant advantage of essentially automatic ownership management, at least for tree-like structures (cycles are more complicated, as always).
What would you propose as a simpler solution? Many languages have GC, which is arguably the simpler solution you speak of, but would be unacceptable in C++, since the large majority of applications it is used for require predictable low-latency responses. Manually managing pointers is how you do things in C, but has it's own sets of problems, since it can't be checked in any way by the compiler, so things like forgetting to free, double free, use after free, etc, are common, while with smart pointers these errors are impossible.