make_shared is a function for creating shared pointers introduced in C++11.
Questions tagged [make-shared]
138 questions
0
votes
0 answers
std::forward and factory that calls std::make_shared
I have code like this...
X* raw = ::new X("abc");
// do something benign to object
std::shared_ptr ptr(raw);
Now consider the same using an object factory...
template
std::shared_ptr factory(A&&... args) {
auto…

user1715587
- 155
- 1
- 10
0
votes
1 answer
C++ newbie: Operation of make_shared
I am new to C++. Can someone please let me know what is wrong with the following code segment -
class Person {
public:
const std::string& name;
Person(const std::string& s): name(s) {}
void dump(void) const {
cout <<…

Jai Prabhu
- 245
- 3
- 10
0
votes
1 answer
Compiler complains make_shared() expects l-value
I have a simple class. One of its constructors takes two int values as arguments:
simple_class.h
class SimpleClass {
private:
int d_ii;
int d_jj;
public:
SimpleClass() : d_ii(40), d_jj(10) {}
SimpleClass( const int ii,…

Daniel Goldfarb
- 6,937
- 5
- 29
- 61
0
votes
1 answer
How does make_shared allocate single dynamic memory for manager object and managed object
make_shared will make a single memory allocation dynamically and hence improves the performance . But how does it make a single memory allocation using new for both managed object and control block .I wanted to know how memory allocation actually…

user2717079
- 299
- 1
- 3
- 13
0
votes
1 answer
make_shared (boost or stl) seems slightly slower than shared_ptr+new in my tests
I have a little doubt concerning what I understand about make_shared performance (boost or stl), so I wanted some opinion.
Working on an app in C++ I had to do some performance tests, and I ended up to compare make_shared and shared_ptr+new (note…

drkmkzs
- 159
- 7
0
votes
1 answer
dynamic_pointer_cast unexpected behaviour
I´m, building a factory class where I need to return a unique_ptr to a BaseClass. The returned pointer is made of a DerivedClass object that is converted to a shared pointer using make_shared and then converted to the desired BaseClass pointer…

Mendes
- 17,489
- 35
- 150
- 263
0
votes
1 answer
Accessing reference variable from shared_ptr
I wasn't sure about the title, so apologies in advance if it's not very clear.
The example below illustrates my problem.
When I use new to initialize the shared_ptr from the Member Initialization List then when I assign a value to the &ref_bar…

Constantinos Glynos
- 2,952
- 2
- 14
- 32
0
votes
2 answers
std::shared_ptr(new DerivedType(...)) != std::make_shared(DerivedType(...))?
I haven't found any issues quite like this yet: but if someone finds one then sorry.
I've been trying to use std::shared_ptr to greatly simplify memory management, however I've come across what must be some sort of bug.
When I create a DerivedType…

Luke Dickety
- 7
- 1
- 4
0
votes
1 answer
Constructor taking shared_ptr
I have situation like this
struct Foo
{
Foo(int x, int y) : x(x), y(y)
{
}
int x, y;
};
class Bar
{
public:
typedef std::shared_ptr ConstFooPtr;
typedef std::shared_ptr FooPtr;
Bar(int index = 0,…

Prazek
- 109
- 1
- 6
0
votes
1 answer
Where does boost::make_shared size of memory allocation for underlying object and reference counting object?
I am trying to understand how boost::make_shared does the memory allocation for the object managed by a boost::shared_ptr and the reference-counting object (the shared_ptr uses) together.
The make_shared function begins execution here:
template<…

user997112
- 29,025
- 43
- 182
- 361
0
votes
1 answer
''className' does not refer to a value' with make_shared
this works:
shared_ptr sp(new ofxDTangibleBase(colorBlob, "ofxDTangibleBase", detectColor, workImg));
But if i do it with make_shared:
shared_ptr sp = make_shared(colorBlob, "ofxDTangibleBase",…

clankill3r
- 9,146
- 20
- 70
- 126
0
votes
1 answer
boost::make_shared and C++Builder VCL objects
I've tried switching some C++Builder 2010 code using new to use boost::make_shared<>, as below.
Old:
boost::shared_ptr l(new TStringList());
New:
boost::shared_ptr l(boost::make_shared());
l->Add("foo");…

Roddy
- 66,617
- 42
- 165
- 277
0
votes
1 answer
Using boost::make_shared with inheritence
Consider two classes
class A{
public:
int i;
A(){}
explicit A(const int ii):i(ii){}
virtual ~A(){
cout<<"~A - "<< i <

zeropoint
- 235
- 1
- 4
- 10
0
votes
1 answer
using make_shared with incomplete types
I am trying to switch my code to use make_shared() but I have a lot of incomplete types (complete at the time of creation) and was wondering if there is anyway make_shared would work with incomplete types or allow me to pass a deleter type.
I…

Sharad
- 1
- 1
-1
votes
1 answer
Using std::make_shared creates strange linker exception
I want to give the user the ability to create a Renderer for drawing objects.
But, the line 'return std::make_shared(this);' creates a strange linker error.
I don't get it fixed.
1> Creating library ..\..\..\bin\Debug\Invision.lib and object…

Pixma
- 11
- 2