5

I want to use smart pointer in my c++ application.

Which header file I should include for using std scoped_ptr?

Vinod
  • 1,076
  • 2
  • 16
  • 33
  • 1
    May I know the reason for vote down – Vinod Jul 23 '12 at 12:13
  • 2
    `scoped_ptr` is not a standard smart pointer, it is [provided by Boost](http://www.boost.org/doc/libs/1_50_0/doc/html/boost/interprocess/scoped_ptr.html). C++11 introduced `std::unique_ptr`, which is similar to `scoped_ptr` with the exception that it is movable. As to the headers where these can be found, this information can very easily be found in the respective documentations. – Luc Touraille Jul 23 '12 at 12:14
  • 3
    I downvoted your question because it does not show any research effort: the StackOverflow users are not a replacement for documentation, where you could have found this information. – Luc Touraille Jul 23 '12 at 12:18
  • For the differences between `boost::scoped_ptr` and `std::unique_ptr`, see [this question](http://stackoverflow.com/q/8199812/20984) and [this one](http://stackoverflow.com/q/3019512/20984). – Luc Touraille Jul 23 '12 at 12:23
  • @LucTouraille Please see this link [link](http://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one) Here, something std::tr1::scoped_ptr is mentioned in Lloyd's answer – Vinod Jul 23 '12 at 12:38
  • @Lloyd's [answer](http://stackoverflow.com/a/106614/981959) is wrong, there is no `std::tr1::scoped_ptr` – Jonathan Wakely Jul 23 '12 at 13:31
  • 2
    @LucTouraille Actually, the boost docs don't explicitly say which header file to use: http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/scoped_ptr.htm - it's buried in example code – Barry Kelly Mar 26 '14 at 16:12

3 Answers3

6

There is no scoped_ptr in the standard C++ library. All C++11 smart pointers are in header <memory>. If you want boost::scoped_ptr then you need boost/scoped_ptr.hpp.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
3

There is no scoped_ptr in the namespace std.
You can either use boost::scoped_ptr from boost.
Or I guess you wanted std::unique_ptr.In this case you need to include <memory>

mkaes
  • 13,781
  • 10
  • 52
  • 72
2

scoped_ptr is a part of Boost library, not standard library.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105