142 questions
2
votes
1
answer
118
views
How can I alias std::make_shared?
I have a template wrapper ThreadSafeVar for convenient mutex-locking of variables, and I want to alias std::shared_ptr and std::make_shared so I can do e.g. ThreadSafePtr<int> a = ...
1
vote
0
answers
111
views
Getting the error munmap_chunk(): invalid pointer: 0x00007ffe53bfa2c0 *** but not using free or malloc
When i do rosrun i get the error of the title but I'm using smart pointers so I don't know why it appears and I'm not using free or malloc. It's about hole avoidance using a robot. IT receives a point ...
0
votes
1
answer
144
views
Can std::make_shared cowork with operator new?
It is said that
std::make_shared uses ::new, so if any special behavior has been set up using a class-specific operator new, it will differ from std::shared_ptr<T>(new T(args...)).
So, given ...
0
votes
0
answers
51
views
std::make_shared<USER_TYRE> initializes user type differently from the std::shared_ptr(new USER_TYRE), where USER_TYRE is a child class to an abstract
I cannot believe my eyes I've meet this problem that seems to be impossible according to documentation. std::make_shared<USER_TYRE> initializes user type differently from the std::shared_ptr(new ...
1
vote
2
answers
3k
views
make_shared returns error C2665: no overloaded function could convert all the argument types
A sample question on c++ primer: Add member named get_file that returns a shared_ptr to the file in the QueryResult object.
class QueryResult
{
friend std::ostream& print(std::ostream&, ...
2
votes
2
answers
177
views
When a thread is executing make_shared, can another thread do something to cause a leak of the object that make_shared creates via new?
From Effective Modern C++, Item 21, I learned that one advantage of std::make_shared over new+std::shared_ptr is that code like this
processWidget(std::shared_ptr<Widget>(new Widget), ...
2
votes
2
answers
690
views
Why make_shared call the destructor even if there are still weak pointer?
From theory, one difference between make_shared() and shared_ptr is the memory allocation technique. make_shared() should use a single block, while shared_ptr should use two blocks.
One make_shared() ...
0
votes
1
answer
84
views
std::shared_ptr C++: How to create for nested struct
#include <iostream>
#include <memory>
using namespace std;
struct buffer{
int buffFilled;
};
struct verifyStruct{
int capacity;
int size;
std::shared_ptr&...
0
votes
2
answers
243
views
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 ...
0
votes
1
answer
277
views
can not compile my code with template and shared_ptr
I have some code :
#include <list>
#include <iostream>
#include <string>
class A
{
private:
std::string field1;
std::string field2;
public :
...
0
votes
1
answer
334
views
How to initialize shared_ptr not knowing its type?
I have a template function, that should get std::shared_ptr<sometype>.
Inside of function I want to make a temporary variable with std::shared_ptr<sometype>, but I can't put sometype as ...
1
vote
3
answers
240
views
Conditional class used in a make_shared with same parameters
Consider this piece of code creating, based on a condition, a different class instance through a std::make_shared. Note that the two possible classes used (Child1 and Child2) are having the same ...
1
vote
1
answer
509
views
Undefined reference to initialized static member variable with make_shared
Compiling with -std=c++14 the following code:
#include <memory>
class A
{
public:
static constexpr int c = 0;
std::shared_ptr<int> b;
A() {
b = std::make_shared&...
1
vote
0
answers
191
views
Why does std::make_shared cause linker errors when using non-inline static const members? [duplicate]
I'm using C++17 and stumbled on a linker error with this kind of code
#include <memory>
struct SomeType
{
static const int MIN = 0;
static const int MAX = 0;
};
struct Range
{
...
3
votes
1
answer
154
views
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 <typename T>
class shared_ptr {
private:
...
public:
shared_ptr(T* p);
shared_ptr(shared_ptr& src);
shared_ptr& ...