Questions tagged [make-shared]

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

138 questions
1
vote
1 answer

std::make_shared and std::forward — what's the point?

I'm trying to understand why std::make_shared is declared/implemented the way it is: template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < !is_array<_Tp>::value, shared_ptr<_Tp> >::type make_shared(_Args&&…
tonytony
  • 1,994
  • 3
  • 20
  • 27
1
vote
1 answer

Why does std::make_shared(Args&&... args) require T to have copy constructor?

I don't understand why a class that has a deleted copy constructor (or contains a member, like ifstream, that has a deleted copy constructor and there it, too, has a deleted copy constructor) can't be used with make_shared()? This code shows what…
Kurt Krueckeberg
  • 1,225
  • 10
  • 11
1
vote
2 answers

Initialise const member with make_shared

The following code compiles using Xcode 6.3.2 but not Visual Studio 2013. #include #include class Y { public: Y(uint32_t i) : m_i(i) { } private: uint32_t m_i; }; class X { public: X() = default; private: …
ksl
  • 4,519
  • 11
  • 65
  • 106
1
vote
1 answer

How can man put a thread(in boost) which is created with packaged_task, into a shared_ptr vector

this is a example from boost library. int calculate_the_answer_to_life_the_universe_and_everything() { return 42; } boost::packaged_task pt(calculate_the_answer_to_life_the_universe_and_everything); boost:: future
rayallen
  • 93
  • 1
  • 1
  • 7
1
vote
1 answer

C++11: 'make_shared' is not a member of 'std'

I'm trying to update some of my code, and tried to include make_shared. I created a class called Mail to send Emails, now i tried to include it: auto m = std::make_shared(); The issue is that I'm using a Makefile: SHELL = /bin/sh SYSTEM…
Michael Schneider
  • 496
  • 1
  • 9
  • 27
1
vote
0 answers

Brace initialization and casting a shared pointer from derived to base class

I am trying to initialize a vector of shared pointers to base class with a number of shared pointers to derived class, using brace initialization. The code (after stripping out irrelevant details) looks like this: #include #include…
1
vote
0 answers

Xcode compile error: Use of undeclared identifier 'make_shared'

I have ported some code which compiles well with VS2012 to Mac. But now the Xcode blurts out an error that it does not recognise the function "make_shared". which is part of c++11. I have declared the following: #include using…
radato
  • 840
  • 9
  • 27
1
vote
2 answers

Trouble constructing shared_ptr

I'm new to smart pointers, and I'm in the process of hitting every stumbling block. I have a struct texture_t: struct texture_t { hash32_t hash; uint32_t width; uint32_t height; uint32_t handle; }; When I try and make a shared_ptr…
Colin Basnett
  • 4,052
  • 2
  • 30
  • 49
1
vote
1 answer

make_shared how to use non default memory management

I have a question about the standard.. So let's say I have pools that manage my memory allocation.. I wanted to use shared_ptr and checked out the API.. As expected, I see that for shared_ptr I control the allocation of the pointer and I can give…
Alon
  • 1,776
  • 13
  • 31
0
votes
1 answer

std::shared_ptr C++: How to create for nested struct

#include #include using namespace std; struct buffer{ int buffFilled; }; struct verifyStruct{ int capacity; int size; std::shared_ptr element; }; int main() { verifyStruct stVerify; …
0
votes
2 answers

How to prove c++11 make_shared() can keep shared_ptr's control block alive even after its dtor?

My question is: is there a case that share_ptr ref count is 0, while weak_ptr ref count is not 0? Difference in make_shared and normal shared_ptr in C++ Referr this thread, showing that if a shared_ptr is created by make_shared and there's weak_ptr,…
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
0
votes
1 answer

can not compile my code with template and shared_ptr

I have some code : #include #include #include class A { private: std::string field1; std::string field2; public : A(std::string const& s1):field1(s1){}; virtual…
0
votes
1 answer

How to initialize shared_ptr not knowing its type?

I have a template function, that should get std::shared_ptr. Inside of function I want to make a temporary variable with std::shared_ptr, but I can't put sometype as template param because I don't know it. #include…
mouse_00
  • 593
  • 3
  • 13
0
votes
1 answer

Compiler error C2664 Cannot convert argument with std::make_shared

This is rather perplexing; I have a class: namespace myApp { class WorldData { public: WorldData(std::string& environmentFile, bool isProduction = false); ... ... }; } #include "myApp.h" using…
nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57
0
votes
1 answer

How to initialize shared pointers in constructor?

I am trying to initialize objects from other classes in my constructor as shared pointers. I need a shred pointer because I need a reference to use in another method in ... header class MyClass { public: MyClass() ; ~MyClass() {}; void…