Questions tagged [make-shared]

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

138 questions
0
votes
2 answers

Does std::make_shared value initialize class members whose default ctor does not initialize?

Does std::make_shared value initalize members when there is a default ctor that fails to initailize its members? I stumbled upon this when using a class where the default ctor did not initialize members using RAII style gave a warning and wondered…
Allan Ojala
  • 694
  • 10
  • 22
0
votes
1 answer

segmentation fault with large number of shared_ptr

this I is my .h file: class Node { public: static void disp(const std::vector &v); static size_t Node_no; Node(const std::vector & initial_state); ~Node(); …
0
votes
2 answers

Why the compiler cannot deduce the template arguments from std::make_shared?

I have this simple question from an exercise in "C++ primer, 5th ed": Exercise 16.38: When we call make_shared (§ 12.1.1, p. 451), we have to provide an explicit template argument. Explain why that argument is needed and how it is used. I've…
Maestro
  • 2,512
  • 9
  • 24
0
votes
2 answers

How to create pointer with `make_shared`

I was looking at this page http://www.bnikolic.co.uk/blog/ql-fx-option-simple.html, on the implementation of shared_pointer. There is one such line - boost::shared_ptr americanExercise(new AmericanExercise(settlementDate, in.maturity)); I…
Daniel
  • 121
  • 6
0
votes
1 answer

Passkey idiom with std::make_shared. xmemory cannot access private Key constructor

In my program I need a factory function that provides instances of separate class because I need control over the details of each instance and to be aware of how many instances are in existence at a time. In particular returning a std::shared_ptr is…
0
votes
0 answers

(Solved User error) c++11 make_shared(new class) memory leak

I've been looking into smart pointers, unit testing how they manage memory and am finding and unexpected issue that all the examples recommend doing, but it creates a huge memory leak for me. This seems to occur when I use a class that has a…
Natio2
  • 235
  • 1
  • 9
0
votes
3 answers

Can make_shared occasionally create duplicate pointers?

I'm failing some of my unit tests about 25% of the time per test. The problem is that when I create an "Entity" object, I use the std::make_shared function to create a pointer to another object. It seems that occasionally, pointers in separate…
0
votes
2 answers

Why make_shared slower than shared_ptr( new T)

In each article it is written that make_shared is more efficient, than shared_ptr(new T), because of one memory allocation not two. But I try this code: #include #include #include #include static const size_t…
BratSinot
  • 9
  • 1
0
votes
1 answer

Problem with initialization of vector of vector of shared_ptr class

I'm trying to initialize a vector of vector of shared_ptr class of size 19x19 ( _goban ). class Goban { public: Goban(); ~Goban(); private: vector>> _goban; }; My constructor is like that : Goban::Goban() :…
Guillaume
  • 191
  • 10
0
votes
0 answers

shared_ptrs destroy themselves after returning from function

I have a vector of shared_ptr but after return from a function call it is Destroyed, but only after returning from the populate function and the elements are the first and the second one [0],[1]. class SettingsFactory { public: explicit…
yaodav
  • 1,126
  • 12
  • 34
0
votes
1 answer

make_shared() reference counting in C++

From: A Tour of C++ (Second edition) 13.2.1 unique_ptr and shared_ptr Using make_shared() is not just more convenient than separately making an object using new and then passing it to a shared_ptr, it is also notably more efficient because it…
Idan Banani
  • 131
  • 2
  • 13
0
votes
1 answer

C++ interface's factory function implementation

Contextualization: I am working on an algorithm of facial recognition and NIST is the organization that is trying to standardize the tests, measurement and comparison among all available algorithms. In order to be tested and compared, I need to…
0
votes
1 answer

C++ std::make_shared

The following code snippet is from the book C++ Concurrency In Action Practical Multithreading page 152, a thread-safe stack class. My question is why the following pop function (of the thread-safe stack class) can't just return…
Alan Zeng
  • 74
  • 1
  • 7
0
votes
0 answers

Error when attempting to use make_shared -- Invalid use of 'sizeof' to incomplete type 'char[]'

I have been trying to dynamically allocate a shared pointer in C++. However, I keep getting the errors /usr/include/boost/make_shared.hpp:15:0: In installation of 'class boost::detail::sp_ms_deleter': In file included from…
0
votes
4 answers

Shared file logging between threads in C++ 11

Recently I started learning C++ 11. I only studied C/C++ for a brief period of time when I was in college.I come from another ecosystem (web development) so as you can imagine I'm relatively new into C++. At the moment I'm studying threads and how…
0x_Anakin
  • 3,229
  • 5
  • 47
  • 86