Questions tagged [boost-smart-ptr]
37 questions
2
votes
4 answers
Convert boost::shared_ptr to actual class
How would someone do that?
for example:
Client* client = it->second;
where it->second is a boost::shared_ptr to Client
error:
cannot convert `const ClientPtr' to `Client*' in initialization
user502230
2
votes
2 answers
Why does boost::scoped_ptr prevent PIMPL idiom with BCB6?
I'm trying to use a boost::scoped_ptr with my implementation class that is visible only in the cpp file of the containing class. The containing class has an explicitly defined destructor (that isn't inline), but my compiler (Borland C++ 5.6.4) fails…

Wolf
- 9,679
- 7
- 62
- 108
1
vote
1 answer
which type of pointer to use for an owned collection of pointers
So , I have done a fair bit of googling trying to figure out if there is some best smart pointer to handle this but I have not been able to settle on a good choice.
struct Car
{
int m_doors;
int m_headlights;
//etc..
}
Lets say I have…

skimon
- 1,149
- 2
- 13
- 26
1
vote
0 answers
Why might my execution path not enter my constructor
My program is short and simple, designed to test my PCA regression class.
#include
#include
#include "data.generator.h"
#include "reg.class.h"
int main(int argc, char* argv[]) {
std::cout << "Flag A" << std::endl;
…

user1289485
- 41
- 3
1
vote
2 answers
How to initialize a shared_ptr as an array of int in C++
I have a class variable defined like this:
std::shared_ptr variable;
I want to make it store ints from 0 to 10
so that when I call variable[1] it returns 1 and so on.

MIA
- 41
- 6
1
vote
0 answers
Disable exception working for boost::smart_ptr but not for boost::property_tree
I'm using boost 1.57.
I need to disable exception support in my not widely-used proprietary compiler.
When I needed to use boost::smart_ptr, the following steps worked like a charm:
Disabled C++11 support using the following user.hpp file…

Valmir
- 401
- 1
- 5
- 14
1
vote
0 answers
Is there any alternatives to boost::intrusive_ptr
I have some code which uses boost::intrusive_ptr. The advantages of using boost::intrusive_ptr over std::shared_ptr is interesting to me. I read about these from these two blogs.
I would like to know if I could replace boost::intrusive_ptr with…

rkm
- 892
- 2
- 16
- 32
1
vote
1 answer
Why is a shared pointer used for the string if the function call results in pass by reference?
In this boost async udp server example:
http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/tutorial/tutdaytime6/src.html
boost::shared_ptr message(
new std::string(make_daytime_string()));
…
user494461
0
votes
1 answer
boost::smart_ptr and COW containers
I'm using boost::scoped_array in a container that I want to make copy-on-write but I fear that scoped_array won't work. Which boost::smart_ptr container is closest to cow-safe scoped array?

moshbear
- 3,282
- 1
- 19
- 33
0
votes
1 answer
Using C++11 with move semantics - without the standard library (and with Boost.smart_ptr)
I’m working on embedded projects, using Zephyr RTOS with ARM embedded microcontrollers like STM32 Nucleo series (Cortex M4/0).
Recently, due to significant C++ support improvements in the recent versions of Zephyr, I’m considering to move from C…

Mishums
- 19
- 6
0
votes
2 answers
passing shared_ptr to std::fstream * EDIT
I had some problem to understand the shared_ptr doc since I am newbie in c++. I hope you could help me with my example code:
#include
#include
#include
#include
#include…

Eagle
- 3,362
- 5
- 34
- 46
0
votes
1 answer
Reading a boost shared_ptr atomically
I have 2 threads that access this one object.
Thread A: updates a boost hared_ptr member
Thread B: reads that boost shared_ptr member
Since a shared_ptr isn't an integer/real pointer type, it cannot be read atomically by Thread B.
I want to avoid…

YeeManB
- 1
0
votes
1 answer
My Auto Pointer works even after ownership transfer
As far as I know, auto_ptr works on the concept of transfer of ownership. Also, once an auto pointer transfer its ownership to another auto pointer, it should not be able refer to the object it points to anymore. However, this is not the case I…

pabitra mohan
- 77
- 1
- 5
0
votes
3 answers
why memory leak when use circular reference in boost::shared_ptr
in the follow code memory leak happened, I have my doubt about that. in the test() fun:
#include
#include
#include
#include
class parent;
class children;
typedef…

yuan su
- 1
- 1
0
votes
1 answer
Is this the correct way to use the boost::scope_ptr with array?
Since boost::scoped_ptr doesn't work with [] indexing operator, I am trying to do a workaround like this
{
boost::scoped_ptr data_ptr;
float *data = new float(SIZE);
data_ptr.reset(data);
...
}
Will the array be freed later…

jcadam
- 983
- 1
- 10
- 18