Questions tagged [scoped-ptr]

A smart pointer provided by Boost that owns a dynamically-allocated pointer and cannot be copied or moved, retaining ownership of the pointer in its scope.

The Boost Smart Pointers library provides the class template boost::scoped_ptr, a smart pointer with non-transferable single-ownership semantics.

scoped_ptr is not in the C++ Standard Library, but const std::unique_ptr is a better replacement for scoped_ptr and scoped_array.

42 questions
1
vote
1 answer

Boost Scoped Ptr - Declaration vs Allocation

The below code is working fine: scoped_ptr pclObjA(new clsA()); But the below statements are not working: scoped_ptr pclObjA; // some statements pclObjA(new clsA()); I am getting compilation error like below: error: no match for call…
sokid
  • 813
  • 3
  • 10
  • 16
1
vote
2 answers

boost::scoped_ptr and STL in C++

I'm reading about boost smart pointers, and one thing I'm not able to grasp is why boost::scoped_ptr can't be used with STL containers? I have read it's non-copyable, but what exactly does that mean and why does STL need that?
darxsys
  • 1,560
  • 4
  • 20
  • 34
0
votes
1 answer

Very fast allocation for objects in scoped_ptr?

Since scoped_ptr guarantees that all objects in a given thread are allocated in a stack-like fashion, what is the least painful way of specifying a "custom heap" for objects under scoped_ptr? (e.g. for vectors, deques, strings, etc.) (This would…
user541686
  • 205,094
  • 128
  • 528
  • 886
0
votes
1 answer

boost::scoped_ptr initialization with other scoped_ptr causes issue. Is this code correct

I am new to boost library and trying boost::scoped_ptr, it states this smart pointer cannot be copied or moved. But I was playing with some code and found an issue. I was able to create new instance of scoped_ptr and initialize it with existing…
Rakesh
  • 21
  • 5
0
votes
1 answer

How to dynamically cast a boost::scoped_ptr?

I'm surprised the compiler refuses to compile this kind of code : class A { virtual ~A() {} }; class B : public A { virtual ~B() {} void foo() {} }; //... boost::scoped_ptr p1(new B); boost::scoped_ptr p2 =…
Caduchon
  • 4,574
  • 4
  • 26
  • 67
0
votes
1 answer

Is there a scoped ptr that has deep copy functionality built in?

As I understand it, if I have a class that has a boost::scoped_ptr member variable, and if I were to copy an instance of that class and would like the new instance to have its scoped_ptr member point to a copy of what the first instance pointed to,…
shadow_map
  • 313
  • 3
  • 15
0
votes
0 answers

scoped_ptr to call member function throws error

I am currently reading Accelerated C++ ch13 and thought of doing sample program given in book via boost scoped_ptr but have encountered an error. May you guys please bail me out. ** ***error: cannot use arrow operator on a type …
samprat
  • 2,150
  • 8
  • 39
  • 73
0
votes
1 answer

scoped_ptr for double pointers

Is there a halfway elegant way to upgrade to following code snipped by the use of boost's scoped_ptr or scoped_array? MyClass** dataPtr = NULL; dataPtr = new MyClass*[num]; memset(dataPtr, 0, sizeof(MyClass*)); allocateData(dataPtr); // allocates…
user1709708
  • 1,557
  • 2
  • 14
  • 27
0
votes
1 answer

boost scoped_ptr/shared_ptr holding memory block of different size than size of object pointed to

Actually when writting this question, another question a shorter one came to my mind so i will ask it first: 1st Question (Shorter): I have a header with struct defined in this manner: typedef struct _CAMERA_LIST { .... }CAMERA_LIST,…
Marcin K.
  • 683
  • 1
  • 9
  • 20
0
votes
0 answers

Erasing Item In std::map with scoped_ptr

Is it safe to remove an item in a std::map with scoped_ptr? Lile, std::map> lmap; boost::scoped_ptr item1(new CFoo); boost::scoped_ptr item2(new CFoo); lmap["item1"] = item1; lmap["item2"] =…
domlao
  • 15,663
  • 34
  • 95
  • 134
0
votes
1 answer

C++ Boost library - passing Shared pointer to a function

Assuming shared pointer can be created as follows typedef boost::shared_ptr srdpointer; srdpointer ptr((Employee_t*)malloc(sizeof(Employee_t)),std::ptr_fun(free)); I need to pass the shared pointer which will allocate memory…
0
votes
2 answers

allocating memory for derived class members based on boost smart pointers in the base class through CRTP

This part of the question provides background information and can be ignored I am working on a template library which heavily relies on the use of the curiously recurring template pattern. The idea behind the class structure is that the user can…
user1391279
1 2
3