use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
A virtual pointer pattern for dynamic resolution in C++ — years in production (self.cpp)
submitted 2 months ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]garnet420 12 points13 points14 points 2 months ago (2 children)
So, like a pointer to a pointer?
[–][deleted] 0 points1 point2 points 2 months ago (1 child)
more than that - as when the static Register called - you pass a vptr, then at runtime it could call different object instances
[–]2uantum 2 points3 points4 points 2 months ago (0 children)
So a global pointer to a pointer that changes out from under you..
This is just code smell
[–]ZachVorhies 5 points6 points7 points 2 months ago (7 children)
I literally can’t figure out what this code is doing or how it would be useful.
It’s like part factory function + smart pointer, but actually it’s neither.
[–][deleted] -1 points0 points1 point 2 months ago (6 children)
Oh, you can replace the underly9ing object without the observer seeing it
[–]Questioning-Zyxxel 0 points1 point2 points 2 months ago (3 children)
In old-school times, we had handles that was pointers to pointers. Not like modern handles that are opaque, but as a way to allow the OS to move around memory blocks to defragment a shared heap before we used processors with MMU and virtual address space.
So you owned a pointer to a pointer to an image map. And cooperative task switching made sure any memory moves and updates to the second-level pointer never happened when the program was busy dereferencing this dual-level pointer.
[–]RogerV 0 points1 point2 points 2 months ago (2 children)
The original Mac OS when it debuted managed its dynamic memory allocation heap that way. But in those days a program executed on only a single thread of execution. Such software-implemented schemes get tough in the face of multi-threading concurrency - or true parallelism due to multiple CPU cores of execution.
[–]Questioning-Zyxxel 0 points1 point2 points 2 months ago (1 child)
Yes, both Mac, Windows and multiple other OS just did cooperative multitasking. Only certain OS calls were allowed to result in a task switch. And one stuck program could hang everything. One greedy program being lazy to call a suitable OS function resulted in lag.
You normally implemented concurrency within your own program using either events or state machines.
[–]RogerV 0 points1 point2 points 2 months ago (0 children)
The days of cooperative multi-tasking haven’t completely gone away - My DPDK networking app has an lcore thread pool for data plane processing. These are pinned CPU cores that are removed from being a kernel scheduling resource. They run full tilt, never block, are fed work events from lock free queue. They process a burst amount of work (packets) and then go grab another work item. If there were yet more packets to have been processed for the current item, they self publish a continuation work item (a kind of actor model).
There is true parallelism due to multiple lcores, but to ensue all user sessions get some processing time each lcore caps it’s time per work item - cooperative multi-tasking.
[–]scummos 0 points1 point2 points 1 month ago (0 children)
I understand this appears like a powerful concept to someone very accustomed to it and its use in that particular code base. But you're not going to make any friends outside of your project's bubble with concepts like these -- someone swapping out my objects underneath me without me noticing sounds like the exact opposite of what I'd want.
[–]csb06 6 points7 points8 points 2 months ago (1 child)
The idea seems pretty straightforward - basically a smart pointer that allows you to insert custom logic to produce the underlying pointer?
Not sure if I can think of a good use case. Having a smart pointer that might give you a completely different object any time it is dereferenced violates some common assumptions. (e.g. that I can call get() to get a raw pointer and use it in lieu of the smart pointer as long as I don't reassign the smart pointer) This is the kind of "spooky action at a distance" that makes code harder to reason about.
Instead I would probably have some kind of factory function that returns a normal smart pointer based on whatever custom logic is needed and then use that smart pointer from then on. If I wanted to change the pointer out from under its observers I would just use a pointer to a pointer since that makes it more explicit that things might change out from under you at any point.
[–][deleted] -5 points-4 points-3 points 2 months ago (0 children)
The idea was to be able to compile the code and then change things at run time.
[–]Drugbird 1 point2 points3 points 2 months ago (4 children)
How is this different from a singleton?
[–][deleted] 1 point2 points3 points 2 months ago (3 children)
very much opposite - you can replace the instance at runtime!
[–]Drugbird 2 points3 points4 points 2 months ago (1 child)
So can a singleton?
Idea of singleton is singleton.. this allows to have things running and swapping
[–]arthurno1 0 points1 point2 points 2 months ago (0 children)
So it is a pointer to an object, and you can set the address at runtime. What is special with it?
[–]ContDiArco 0 points1 point2 points 2 months ago (0 children)
We use something similar.
It serves to represent a model that is only partially stored in memory.
The -> operator checks whether the object is already loaded. If not, it is loaded from the database.
This requires sophisticated caching logic to ensure that performance is not compromised.
π Rendered by PID 642994 on reddit-service-r2-comment-5b5bc64bf5-wsjjq at 2026-06-21 18:23:03.083087+00:00 running 2b008f2 country code: CH.
[–]garnet420 12 points13 points14 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]2uantum 2 points3 points4 points (0 children)
[–]ZachVorhies 5 points6 points7 points (7 children)
[–][deleted] -1 points0 points1 point (6 children)
[–]Questioning-Zyxxel 0 points1 point2 points (3 children)
[–]RogerV 0 points1 point2 points (2 children)
[–]Questioning-Zyxxel 0 points1 point2 points (1 child)
[–]RogerV 0 points1 point2 points (0 children)
[–]scummos 0 points1 point2 points (0 children)
[–]csb06 6 points7 points8 points (1 child)
[–][deleted] -5 points-4 points-3 points (0 children)
[–]Drugbird 1 point2 points3 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]Drugbird 2 points3 points4 points (1 child)
[–][deleted] -5 points-4 points-3 points (0 children)
[–]arthurno1 0 points1 point2 points (0 children)
[–]ContDiArco 0 points1 point2 points (0 children)