Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
130 views

As I understand it, std::polymorphic<T> and std::indirect<T> are const-propagating wrapper types for an owning pointer to a T object, where the target of the pointer is copied with the ...
dumbass's user avatar
  • 27.2k
-3 votes
1 answer
132 views

I am trying to create Linkedlist, where array is passed, and linkedlist is returned. However, there seems something wrong, and the linkedlist returned is circular. /** * Shared pointer, pass vector ...
Susobhan Das's user avatar
  • 1,310
0 votes
1 answer
182 views

How does the implementation of C++ std::weak_ptr upgrade to std::shared_ptr and access the object without risking a use-after-free? The scenario: In a concurrent setting, you have a weak pointer to an ...
Qwert Yuiop's user avatar
1 vote
1 answer
148 views

Hope this message finds you well. I'm a little bit lost while using trompeloeil expectations syntax. Let's say I have this: #include <memory> class IA { public: virtual ~IA() = default; ...
anthonyNk's user avatar
3 votes
1 answer
176 views

I'm attempting to make a game in C++ where pieces will move around a gameboard. In our team, we're trying to be good and use as much modern methodology as we can, given we've gotten rusty and now have ...
Force Gaia's user avatar
5 votes
0 answers
250 views

In this earlier SO question: What is a smart pointer and when should I use one? Ten years ago, I gave a relative simple answer and got a bunch of upvotes. One paragraph in my answer reads: Use std::...
einpoklum's user avatar
  • 137k
0 votes
2 answers
311 views

Let's say you allocate an object and pass its address in a Windows message (posted, not sent). In the message handler, the address is recovered and used to initialize a std::unique_ptr. Will the ...
0___________'s user avatar
  • 71.6k
2 votes
4 answers
315 views

I have this existing working code, which I am trying to convert to implementation: Bitmap *pbitmap = new Bitmap(L"images.png"); nWidth = pbitmap->GetWidth(); nHeight = pbitmap->...
Gorlash's user avatar
  • 81
1 vote
2 answers
100 views

#include <cstddef> #include <stdexcept> #include <cassert> template <typename T> class Pointer { private: std::ptrdiff_t offset; std::ptrdiff_t calculateOffset(const ...
Tejas Sharma's user avatar
3 votes
1 answer
126 views

I have the following minimal reproducible example where it seems that my unique-pointer-containing object B is not allowed to contain a unique pointer to another instance of B: #include <iostream&...
Featherball's user avatar
1 vote
0 answers
46 views

Intrusive shared pointers have some advantages over classical control block shared pointers, as they allow, as far as I understand, atomic, lock-free concurrent operations with single writer and ...
galinette's user avatar
  • 9,420
1 vote
1 answer
152 views

I wrote a toy raytracer following the popular raytracing in one weekend series that uses heavily shared_ptr for more or less everything. The codebase in nice and tidy but extremely slow (a 400x400 ...
Niccolò Tiezzi's user avatar
3 votes
1 answer
140 views

I am writing a UI framework for a microcontroller, in which I want to do a hierarchical menu system. For that in particular I have the following classes: class MenuNode { public: MenuNode(const ...
akasaka's user avatar
  • 322
2 votes
1 answer
148 views

I was experimenting with std::unique_ptr and reference-type deleters, and noticed that it does not allow polymorphic conversion when moving a unique_ptr with a derived-class deleter into one expecting ...
yqZhang4480's user avatar
3 votes
3 answers
260 views

I hope this question will find you well. I'm a little puzzled on this one. I really don't understand how Qt Object model tree handles memory with smart pointers. I created this Qt5 basic test app just ...
anthonyNk's user avatar
4 votes
3 answers
139 views

I have have found the following code in my company's codebase. The logic behind is to free the config singleton when nobody is using it, as some users have been found to inflate its size, which has ...
Dominik Kaszewski's user avatar
-3 votes
2 answers
168 views

I am developing a game in C++, and have been using vectors of smart pointers to store some level data. The game runs and works without issue, but I was wondering whether or not the memory held by the ...
Fishie's user avatar
  • 37
3 votes
1 answer
76 views

I have a custom smart pointer which I'm trying to extend to trait objects. Essentially what I'm trying to make is the following: use std::ptr::NonNull; struct Ptr<T: ?Sized> { data: NonNull&...
Jared Dewey's user avatar
3 votes
2 answers
135 views

I wanted to capture std::unique_ptr into lambda and then move it into another function inside lambda, but my two minimal examples fail to compile and I'm not sure why. Can somebody explain to me, why ...
Semyon Burov's user avatar
  • 1,182
1 vote
0 answers
50 views

I created a smart Pointer using Boost Lib : boost::shared_array<int> spArray = nullptr; Then, I let it manage a 16bit aligned memory: spArray.reset((int *)memalign(16, 100 * sizeof(int))); The ...
JaveLin's user avatar
  • 21
0 votes
0 answers
61 views

I'm a bit confused about how to handle the different reference and smart pointer types in this example: use std::rc::Rc; use std::sync::Arc; struct Data{} trait ApiClient { fn load_data() -> ...
Cedd0's user avatar
  • 65
0 votes
0 answers
54 views

Brief I have a C++ library that provides sort of Sender and Listener functionality. The Listener class is pure virtual class that is intended to be extended by the client. The Sender class accepts ...
Evan Altair's user avatar
1 vote
2 answers
115 views

When using the fftw3 fast fourier transform (FFT) library, a plan variable is declared and initialised, it is then used to perform some FFTs and subsequently destroyed when the memory is to be freed: #...
Climbatized's user avatar
0 votes
3 answers
166 views

How to put std::function in a smart pointer like std::unique_ptr and use it? I have already tried but it didn't work. Here is the code that I tried already: const inline void PrintSection(TurboINI::...
Александр Алибеков's user avatar
2 votes
2 answers
135 views

I'm working on a game, represented by the Game class, which owns every GameEntity and stores them in a container. However, for convenience my Game class would also like to have a dedicated container ...
Will F's user avatar
  • 31
2 votes
4 answers
484 views

I have some hierarchy (through composition, not inheritance) of classes: Child and Parent. Child can have multiple parents, also Parent could do the same. I want the Child class lifetime being managed ...
Supreme Machine's user avatar
0 votes
1 answer
119 views

I'm trying to create a game in C++, using SDL. My structure for the game-code in the main is like this: Create object game. (create NEEDED objects such as the SDL window or camera) Call function ...
Blib's user avatar
  • 9
0 votes
1 answer
167 views

Can I create and use C++ smart pointers for different pointer types from FFmpeg? "AVCodecContext *" which is used only as a pointer in all functions except deallocation. Alloc: ...
Elija's user avatar
  • 101
4 votes
1 answer
197 views

The cppreference.com's entry on weak_ptr::use_count includes the caveat: The usage and behavior of this function are similar to std::shared_ptr::use_count, but it returns a different count. Since it'...
cebola's user avatar
  • 314
1 vote
1 answer
260 views

I want to use the c++ httplib feature of the server to send a content with a content provider. But I want to use it with a smart pointer because of previous calculation doing before the dispatch. If I ...
Theo's user avatar
  • 43
-1 votes
1 answer
160 views

When I run this code: #include <memory> #include <iostream> class A { public: virtual std::unique_ptr<A> clone() = 0; }; class B : public A { private: int b0; public: B(const B&...
Dani's user avatar
  • 19
0 votes
2 answers
84 views

With below code snippet is it ever possible that output will print "Shared Ptr out of scope"? What I am trying is before a shared copy is made the orginal shard_ptr goes out of scope. I am ...
Rakesh Mehta's user avatar
2 votes
1 answer
125 views

Question: I have a C++ program using std::shared_ptr and std::weak_ptr involving two classes, A and B. The program creates shared pointers for both classes and sets up a relationship between them, ...
哈哈哇's user avatar
-2 votes
1 answer
105 views

I would like to see two object printing from two different derived classes, and the key is to cast the object to derived class after being define as base. Here is the code: #include <iostream> #...
Nick X Tsui's user avatar
  • 2,922
0 votes
1 answer
85 views

I am trying to get a class object (with a unique_ptr member) from a std::map (previously filled), and error occurs. Here is the code: classes.hpp #ifndef CLASSMETHODNOTCALLED_CLASSES_HPP #define ...
Nick X Tsui's user avatar
  • 2,922
0 votes
1 answer
112 views

I'd like a member function to return a unique_ptr reference to a const type, just like in raw pointers. Here is what I mean: class Foo { private: int _number; public: [[nodiscard]] ...
rdabra's user avatar
  • 138
0 votes
1 answer
126 views

In the code bellow, when using std::shared_ptr I get a segmentation fault. However, when using normal pointers, the same problem doesn't occur. In summary, I want to define a ConstrainedVariable ...
Pedro Xavier's user avatar
5 votes
3 answers
117 views

I'm implementing an A* pathfinding algorithm in C++ to solve a maze, but I'm encountering a segmentation fault (SIGSEGV) when the maze size is high (~10,000x10,000 or larger). The error occurs in the ...
hubenhau's user avatar
1 vote
1 answer
87 views

I'm writing a simple compiler and I have a base class: class Instruction { public: virtual std::string get_name() const = 0; }; I create an instruction such as Compute: class Compute : public ...
Thomas Matthews's user avatar
2 votes
2 answers
180 views

I am playing around with C++ and faced this problem. If I have a variant that looks like this: using Fruit = variant<Apple, Tomato> and a vector of unique_ptr of Fruit: vector<unique_ptr<...
HiddenPasta's user avatar
-1 votes
1 answer
89 views

Given this code: class Clazz { private: std::shared_ptr<int> something; public: Clazz() : something(std::make_shared<int>(0)) {} int &getSomething() { return *something; ...
tjzel's user avatar
  • 115
2 votes
2 answers
146 views

I am following this tutorial to understand how to return smart pointers and covariance in C++. #include <memory> #include <iostream> class cloneable { public: virtual ~...
GPrathap's user avatar
  • 7,870
2 votes
3 answers
290 views

In the Rust book an example is provided in chapter 15 section 3 to show when Rust runs the drop function on the variables c and d. struct CustomSmartPointer { data: String, } impl Drop for ...
Anthony Ruiz's user avatar
0 votes
1 answer
198 views

First, I read this answer to realize why we want to convert an unique_ptr to a shared_ptr sometimes. Then, I follow the instructions of the converting constructor on cppreference shared_ptr. In C++11 ...
Rock's user avatar
  • 188
0 votes
1 answer
76 views

I am trying to write my own implementation of unique_ptr in C++, and here is my UniquePtr header file: #include <iostream> template <typename T> class UniquePtr { T* ptr; public: ...
user25687822's user avatar
1 vote
0 answers
154 views

I have a scenario where I need to use weak_ptr to cache resource, and use shared_ptr externally to determine the life cycle of the resource. When applying for this resource, I must ensure that it was ...
x f's user avatar
  • 93
0 votes
0 answers
106 views

I currently have this problem with a std::shared_ptr. Or at least, I think the problem is there. I have an app whose input data are passed through an interface from the calling program to the app ...
egev's user avatar
  • 51
2 votes
2 answers
100 views

The code snippet below always closes the connection at once when a client has connected to the server, which is really out of my expectation. #include <iostream> #include <memory> #include ...
John's user avatar
  • 3,574
0 votes
1 answer
64 views

The code below is seen at this SO except the comment in the original question has been removed. std::weak_ptr<int> g_w; void f3() { std::shared_ptr<int>l_s3 = g_w.lock(); //2. here ...
John's user avatar
  • 3,574
2 votes
1 answer
116 views

How std::weak_ptr::lock() is implemented to garantee both shared_ptr and weak_ptr can be used from threads without further synchronization(see the example code). As per the cppreference, which says ...
John's user avatar
  • 3,574

1
2 3 4 5
58