Questions tagged [make-shared]

make_shared is a function for creating shared pointers introduced in C++11.

138 questions
5
votes
2 answers

Strange error trying to do a shared_ptr swap()

I'm a relative C++ newbie trying to convert an existing project from raw pointers, with a convoluted memory-management protocol, over to using C++11's shared_ptr. Overall it is going very smoothly, and I think I understand how shared_ptr works in…
bhaller
  • 1,803
  • 15
  • 24
5
votes
2 answers

how to create boost phoenix make_shared?

Is it possible to create boost phoenix lazy variant of std::make_shared? I mean, to make possible something like namespace p = boost::phoenix; ... expr = custom_parser[_a=p::make_shared(_1,_2,_3)] >> ... One cannot use…
polytheme
  • 51
  • 1
5
votes
1 answer

C++ Supply initializer-list constructor for class template

I have a class template Templ with template parameter T, and the Templ class has a data member of type T, called obj. I wrote a variadic constructor template which forwards the arguments to obj's constructor: template class…
4
votes
3 answers

Shared pointers not increasing the use_count

I'm trying to get an idea on how to use std::shared_ptr in C++. But it's pretty confusing and I don't understand how to create multiple shared pointers pointing to the same object. Even the documentation and online material is not very…
Dee Jay
  • 109
  • 1
  • 7
4
votes
2 answers

What is make_shared of unknown size?

In this answer T.C. states boost::make_shared etc. support array types - either one of unknown size, or one of fixed size boost::shared_ptr sh_arr2 = boost::make_shared(30); boost::shared_ptr sh_arr3 =…
jacknad
  • 13,483
  • 40
  • 124
  • 194
4
votes
0 answers

Why do signatures of make_shared and allocate_shared differ for the args to be forwarded?

In order to create a std::shared_ptr for a given type T, there are two ways among the others: std::allocate_shared and std::make_shared. The main difference (or at least, the one I'm interested in for this question) is that the former does all…
skypjack
  • 49,335
  • 19
  • 95
  • 187
4
votes
1 answer

Error: no instance of overloaded function "std::make_shared" matches the argument list

Looking at A previous stack Question of std:make_shared vs std::shared_ptr, I have tried to implement this in a uni project. This was the previous 'question': I can't think of any situation where std::shared_ptr obj(new Object("foo",…
Steven C
  • 45
  • 1
  • 2
  • 7
3
votes
1 answer

Debuggable replacement for make_shared()

Using gcc 4.6.2, make_shared() gives a useless backtrace (apparently due to some rethrow) if a constructor throws an exception. I'm using make_shared() to save a bit of typing, but this is show stopper. I've created a substitute make_shrd() that…
srking
  • 4,512
  • 1
  • 30
  • 46
3
votes
1 answer

'boost::make_shared' : ambiguous call to overloaded function

I've got the following class definition: class Portal { public: Portal( const vector &vertices, shared_ptr target ); ... }; Somewhere else, I want to create an instanceof said class like this: auto portal =…
vexator
  • 427
  • 1
  • 7
  • 16
3
votes
1 answer

Why it needs a rvalue copy constructor even it won't be called?

I've wrote a shared_ptr the class definition is as below: template class shared_ptr { private: ... public: shared_ptr(T* p); shared_ptr(shared_ptr& src); shared_ptr& operator=(shared_ptr const& src); }; shared_ptr
Pan
  • 125
  • 2
  • 5
3
votes
1 answer

How to call std::make_shared in case of initializer_list arguments?

I am trying to use std::make_shared for object construction on heap in my program instead of new, but when object constructor is supplied with initializer list the simple replacement does not work and I have to manually specify exact type: #include…
Fedor
  • 17,146
  • 13
  • 40
  • 131
3
votes
4 answers

Using make_shared with emplace_back and push_back - any difference?

some_vector.push_back(make_shared()); some_vector.emplace_back(make_shared()); I want to check that my understanding is correct that for make_shared and in general for all other functions that returns an object those two calls…
Johy
  • 263
  • 2
  • 10
3
votes
1 answer

Is it possible that make_shared has no any exception but returns a nullptr?

I am recently dealing with a problem with shared_ptr. I am curious if make_shared failed, it will raise exceptions right? Is there any kind of situation that the make_shared returned a nullptr but without any exceptions?
Alex Lee
  • 309
  • 3
  • 11
3
votes
3 answers

All shared_ptr refer to the same pointer in my vector

I created a vector of vector of shared_ptr class (_cells). class Goban { public: Goban(); ~Goban(); private: vector>> _cells; }; I initialize like that : Goban::Goban() : _cells(18,…
Guillaume
  • 191
  • 10
3
votes
3 answers

how to block usage of std::make_shared

I know I can prevent ordinary heap allocation of custom class and its descendants by making the class's operator new private, but is there any way to prevent a user of a library from calling std::make_shared on a custom class (or its descendants)? …
markt1964
  • 2,638
  • 2
  • 22
  • 54
1 2
3
9 10