Reputation:
I was asked this in an interview. Seems boost library has something called scoped_pointer. Not sure if he asked about that.
Upvotes: 0
Views: 1029
Reputation: 28872
Boost does have a scoped_ptr
.
Boost Docs
The primary reason to use scoped_ptr rather than auto_ptr is to let readers of your code know that you intend "resource acquisition is initialization" >to be applied only for the current scope, and have no intent to transfer ownership.
A secondary reason to use scoped_ptr is to prevent a later maintenance programmer from adding a function that transfers ownership by returning the auto_ptr, because the maintenance programmer saw auto_ptr, and assumed ownership could safely be transferred.
Think of bool vs int. We all know that under the covers bool is usually just an int. Indeed, some argued against including bool in the C++ standard because of that. But by coding bool rather than int, you tell your readers what your intent is. Same with scoped_ptr; by using it you are signaling intent.
It has been suggested that scoped_ptr is equivalent to std::auto_ptr const. Ed Brey pointed out, however, that reset will not work on a std::auto_ptr const.
Upvotes: 1
Reputation: 1
The term most probably referred to the c++ smart-pointers category, which provides scoped owner management for pointers.
Upvotes: 1