Auto ptr why




















I found the existing answers great, but from the PoV of the pointers. Multiple threads, of course is another example. For the 3. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 11 years, 2 months ago. Active 3 years, 8 months ago. Viewed 47k times. What is the reason for this? Improve this question. Add a comment.

Active Oldest Votes. Improve this answer. Jerry Coffin Jerry Coffin k 74 74 gold badges silver badges bronze badges.

HowardHinnant interesting doc! To be usable with the AutoPtr template, a class must implement the following behaviour: A class must maintain a reference count.

The constructors of the object initialize the reference count to one. The class must implement a public duplicate method:. AutoPtr works in the following way: If an AutoPtr is assigned an ordinary pointer to an object via the constructor or the assignment operator , it takes ownership of the object and the object's reference count remains unchanged. If the AutoPtr is assigned another AutoPtr , the object's reference count is incremented by one by calling duplicate on its object.

Hence, the stored pointer must not be null, and Type must be a class, struct, or union type with a member member. The member replaces the stored pointer myptr with a null pointer and returns the previously stored pointer. The member function evaluates the expression delete myptr , but only if the stored pointer value myptr changes as a result of a function call. It then replaces the stored pointer with ptr. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services.

Privacy policy. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info.



0コメント

  • 1000 / 1000