I was asked this in an interview. Seems boost library has something called scoped_pointer. Not sure if he asked about that.
-
"scope pointer" or "scoped pointer"? – 463035818_is_not_an_ai May 27 '16 at 16:45
-
Well a pointer can't address a scope, so scoped_ptr sounds like a reasonable assumption. – Captain Giraffe May 27 '16 at 16:46
-
"What is called a scope pointer in C++ ?" -- Is that the question you were asked verbatim? I'm guessing not and I'd guess they were asking about smart pointers and RAII in general (perhaps `std::unique_ptr` specifically) ... – James Adkison May 27 '16 at 16:46
-
http://stackoverflow.com/questions/8199812/difference-between-boostscoped-ptrt-and-stdunique-ptrt – Captain Giraffe May 27 '16 at 16:46
-
Worth reading: http://stackoverflow.com/questions/395123/raii-and-smart-pointers-in-c – May 27 '16 at 16:56
-
@JamesAdkison I'll bet the verbatim question was asked in another language, and he's translating for our benefit. – Barmar May 27 '16 at 17:04
-
@Barmar Valid point, quite possible. – James Adkison May 27 '16 at 17:13
2 Answers
The term most probably referred to the c++ smart-pointers category, which provides scoped owner management for pointers.

- 1
- 13
- 116
- 190
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.