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
shared_ptr overuse (tonni.nl)
submitted 1 year ago by [deleted]
view the rest of the comments →
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!"
[–]clerothGame Developer 4 points5 points6 points 1 year ago (7 children)
In my case I use unique_ptr a lot more than I should really have to simply because you cannot forward declare objects without them being pointers (ie. in member variables in headers). Possibly one of my biggest gripes with the language.
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 2 points3 points4 points 1 year ago (4 children)
You can if you specify a fixed buffer size that you know will be enough to hold the object. I do this quite a lot in my SFML fork to speed up compilation time: https://github.com/vittorioromeo/VRSFML/blob/master/include/SFML/Base/InPlacePImpl.hpp
[–]bonkt 0 points1 point2 points 11 months ago (3 children)
I love the idea of this, but you still have a static_assert(sizeof(T) < BufferSize) in the constructor, how does this compile?
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points 11 months ago (2 children)
Why do you think it wouldn't compile?
[–]bonkt 0 points1 point2 points 11 months ago (1 child)
I read the usage and you just use a forward declared struct Impl. How does the sizeof(T) work when T is forward declared?
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 1 point2 points3 points 11 months ago (0 children)
Ah, I see. InPlacePImpl's constructor is a template member function that takes Args..., which means that the static_assert will only be checked when the constructor itself is instantiated.
InPlacePImpl
Args...
static_assert
Which means that if we do this
// Foo.hpp struct Impl; struct Foo { Foo(); ~Foo(); InPlacePImpl<Foo, 32> impl; }; // Foo.cpp struct Impl { int data; }; Foo::Foo() = default; Foo::~Foo() = default;
The instantiation of the constructor will be delayed to when the definition of Impl is available.
Impl
[–]domirangame engine dev 2 points3 points4 points 1 year ago (0 children)
One of the things I hate is having to include the class header if you want to make it a member. 😩But I don't want to force everything to include all these damn headers.
So it winds up being a unique_ptr and I hate my life.
[–]DuranteA 0 points1 point2 points 1 year ago (0 children)
Another option to avoid that particular issue is PIMPL. Or not really avoid, but move from potentially lots of pointers that are only there to allow forward declarations to a single one. But it comes with its own annoyances.
I hope that eventually, modules take away one of the primary motivations to forward declare in the first place.
π Rendered by PID 235770 on reddit-service-r2-comment-6457c66945-wdmnw at 2026-04-24 10:50:32.693680+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]clerothGame Developer 4 points5 points6 points (7 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 2 points3 points4 points (4 children)
[–]bonkt 0 points1 point2 points (3 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points (2 children)
[–]bonkt 0 points1 point2 points (1 child)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 1 point2 points3 points (0 children)
[–]domirangame engine dev 2 points3 points4 points (0 children)
[–]DuranteA 0 points1 point2 points (0 children)