2,870 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
Best practices
0
votes
2
replies
91
views
How should I store a dyn FnMut in a struct?
I'm trying to make a struct that has dynamic methods by storing FnMuts in the struct. The FnMuts would be a function written in a scripting language like Python or Lua, but there might be some cases ...
4
votes
1
answer
147
views
Why can’t I efficiently move-construct `std::polymorphic<Base>` from `std::polymorphic<Derived>`?
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 ...
-3
votes
1
answer
135
views
Linkedlist create like below with shared_ptr is proper or wrong - [closed]
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 ...
0
votes
1
answer
193
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?
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 ...
1
vote
1
answer
153
views
How to handle return of unique_ptr in trompeloeil RETURN expectations
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;
...
3
votes
1
answer
181
views
Smart pointers and polymorphism - Use in a model class is causing casting issues
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 ...
5
votes
0
answers
252
views
Am I over-encouraging people to use shared_ptr's? [closed]
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::...
-1
votes
2
answers
325
views
Will unique pointer free the memory? [duplicate]
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 ...
2
votes
4
answers
319
views
std::vector: when is a pointer not a pointer?
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->...
1
vote
2
answers
102
views
invalid user-defined conversion from Pointer<Node> to Node*
#include <cstddef>
#include <stdexcept>
#include <cassert>
template <typename T>
class Pointer {
private:
std::ptrdiff_t offset;
std::ptrdiff_t calculateOffset(const ...
3
votes
1
answer
127
views
Can an object that owns a unique pointer be unique pointed to?
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&...
1
vote
0
answers
47
views
Atomic implementation of intrusive shared pointers allowing construction from another being destroyed
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 ...
1
vote
1
answer
154
views
Smart pointers vs raw pointers for raytracer [closed]
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 ...
3
votes
1
answer
141
views
How to prevent code heavily relying on polymorphism from being littered with `make_shared` all over the place?
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 ...
2
votes
1
answer
154
views
Why doesn't std::unique_ptr allow polymorphic conversion for reference-type deleters?
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 ...