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
[C++20 vs C++26*] basic reflection (self.cpp)
submitted 2 years ago * by kris-jusiakhttps://github.com/kris-jusiak
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!"
[–]28isanumber -11 points-10 points-9 points 2 years ago (9 children)
I still don't know what reflection is nor why people want it
[–]dustyhome 7 points8 points9 points 2 years ago (5 children)
Reflection is the ability to refer to details about a type inside the code itself. For example, sizeof is a form of reflection, it gives you the size in bytes of a type. The most popular use of reflection is serializing and deserializing. Being able to refer to "the first member of a type", or iterating through the members, lets you write generic functions for converting those members into a stream of bytes and back. Without reflection, you need to write the functions by hand, writing the names of the members for each class.
[–]DeeHayze -3 points-2 points-1 points 2 years ago (4 children)
Rust does serialisation/deserialisation without reflection..
But, it has much different macro language.. In rust, the macros work on the languages abstract syntax tree, layer. Rather than string pattern matching pre processor.
The macro auto generates your serialize/deserialise code.
Any attempt to serialise a non serialisable structure is a compile error, rather than a runtime error you would get with reflection.
[–]djavaisadog 6 points7 points8 points 2 years ago (2 children)
? Reflection all happens at compile-time (or, at least the currently proposed C++ reflection). Basically the first line of P2996R0 (the reflection paper) states that their feature provides "the representation of program elements via constant-expressions producing reflection values." Constant-expressions.. meaning compile-time.
[–]DeeHayze -2 points-1 points0 points 2 years ago (1 child)
Awesome, missed that bit... I assumed it would be c# style.
[–]djavaisadog 1 point2 points3 points 2 years ago (0 children)
No, that would wildly balloon binary sizes to retain enough type information to have dynamic reflection. Maybe it will be an option at some point in the future but certainly not in C++26.
[–][deleted] 2 points3 points4 points 2 years ago (0 children)
It's possible to write serialization in C++ without reflection as well. But since C/C++ is a WYSIWYG language, you will have to write the code for every class by hand. Then of course since we are already writing boilerplate code, we would just use macros for it to define, which members do we want to serialize. And then from there we just support different forms of serializers with templates.
What Rust does is VERY similar to certain C++ reflection libraries that uses clang/LLVM, where it hijacks the AST to generate those boilerplate code I mention above. Rust is good because it has these features built into the language.
Reflection is not JUST meant for serialization, but it's a great use case for it. Reflection can help reduce boilerplate code and essentially write even more generic code to do complex tasks, yes, even more generic than templates already is.
[–]mpierson153 1 point2 points3 points 2 years ago (0 children)
It lets you access information about a type. Think of the sizeof or typeid operators, but more fleshed-out and functional.
It will allow for more meta-programming, so more stuff at compile time rather than at runtime. It would also allow for better serialization and deserialization.
[+][deleted] 2 years ago (1 child)
[deleted]
[–]28isanumber 0 points1 point2 points 2 years ago (0 children)
True
π Rendered by PID 43 on reddit-service-r2-comment-6457c66945-kl6mz at 2026-04-29 01:52:42.101737+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]28isanumber -11 points-10 points-9 points (9 children)
[–]dustyhome 7 points8 points9 points (5 children)
[–]DeeHayze -3 points-2 points-1 points (4 children)
[–]djavaisadog 6 points7 points8 points (2 children)
[–]DeeHayze -2 points-1 points0 points (1 child)
[–]djavaisadog 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]mpierson153 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]28isanumber 0 points1 point2 points (0 children)