Description
Assume we have a user-defined type A
:
struct A {
void reset() { /* A's own logic to reset something */ }
};
And then this type was instantiated using std::unique_ptr
(std::shared_ptr
also acceptable):
auto a = std::make_unique<A>();
Since both std::unique_ptr
and A
have reset
method with different meaning, it might be ambiguous to use them:
a->reset(); // performs the logic defined in A, "a" stays alive
a.reset(); // "a" becomes nullptr
It might be surprised for a programmer to call not the reset
he expects(more over it might be bugproned), and it's easy to make such typo because the difference between .
and ->
really small.
Suppose the code above might be changed in a better(more clear) way:
a.get()->reset(); // performs the logic defined in A, "a" stays alive
a = nullptr; // "a" becomes nullptr