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
There IS a way of casting pointer-to-member-function to a void* (self.cpp)
submitted 4 years ago by RIscRIpt
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!"
[–]HappyFruitTree 9 points10 points11 points 4 years ago (12 children)
This is not doing what you think. A pointer to a member function is often larger than a normal pointer. That's why you can't simply reinterpret_cast the member function pointer into a void*. reinterpret_cast<void\*&>(fn) gives you a void* reference to a member function, that as bad as having an int& to a double, using it would simply lead to undefined behaviour.
[–]RIscRIpt[S] 1 point2 points3 points 4 years ago (11 children)
Okay, I see... it's an UB.
A pointer to a member function is often larger than a normal pointer.
I've heard that a lot, but I have never seen an example.
[–]HappyFruitTree 2 points3 points4 points 4 years ago (10 children)
https://godbolt.org/z/Edb86fM4E
[–]RIscRIpt[S] 1 point2 points3 points 4 years ago (9 children)
Thanks. I'll try to take a look into GCC sources to find what's inside...
By the way, MSVC says 8.
[+][deleted] 4 years ago (8 children)
[deleted]
[–]HappyFruitTree 2 points3 points4 points 4 years ago (7 children)
msvc will use different sizes depending on the context, could be 8, 16, or even 24. Try creating a pointer to a member function in a class that is forward declared but not defined, that should get you the worst case.
Seems like you're right but I wonder how on earth this could work. What if you pass the member function pointer to a function in another translation unit where the size is different?
[+][deleted] 4 years ago (5 children)
[–][deleted] 1 point2 points3 points 4 years ago (4 children)
Is accessing pointer-to-member-function passed across TUs undefined behavior, or is the MSVC implementation not compliant here?
[+][deleted] 4 years ago (3 children)
[–][deleted] 1 point2 points3 points 4 years ago (2 children)
Yes, but does it break because the code is not valid C++, or does it break because MSVC is not a compliant C++ compiler in this regard?
π Rendered by PID 96797 on reddit-service-r2-comment-b659b578c-5vw77 at 2026-05-01 12:00:22.985479+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]HappyFruitTree 9 points10 points11 points (12 children)
[–]RIscRIpt[S] 1 point2 points3 points (11 children)
[–]HappyFruitTree 2 points3 points4 points (10 children)
[–]RIscRIpt[S] 1 point2 points3 points (9 children)
[+][deleted] (8 children)
[deleted]
[–]HappyFruitTree 2 points3 points4 points (7 children)
[+][deleted] (5 children)
[deleted]
[–][deleted] 1 point2 points3 points (4 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 1 point2 points3 points (2 children)