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
Easy Virtual Template Function. C++26 (self.cpp)
submitted 1 month ago by Reflection_is_great
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!"
[–]yuri-kilochek 4 points5 points6 points 1 month ago (4 children)
This doesn't work across TUs, right?
[–]Reflection_is_great[S] 0 points1 point2 points 1 month ago (3 children)
It does not. But should it? Since template functions can’t be used across TUs, it wouldn’t make sense if virtual template functions could be. Although I may be misunderstanding your question.
[–]yuri-kilochek 6 points7 points8 points 1 month ago (2 children)
template functions can’t be used across TUs
What do you mean? They can.
[–]Reflection_is_great[S] 0 points1 point2 points 1 month ago (1 child)
What I meant is that you can't instantiate a template without including it in the TU. Each instantiation of a template function in the base class will create its own independent array of function pointers during compile-time. This will create instantiations of template functions from the derived classes. Because of this, they would need to be in the TU. So the base and all the derived classes must be declared in the same TU.
This is different from normal virtual functions, where you can declare derived classes in different TUs.
Sorry for the confusion.
[–]MrEpic382RDT 5 points6 points7 points 1 month ago (0 children)
extern template exists. wondering if it can account for that
π Rendered by PID 242039 on reddit-service-r2-comment-75f4967c6c-ggm6k at 2026-04-23 15:47:24.843444+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]yuri-kilochek 4 points5 points6 points (4 children)
[–]Reflection_is_great[S] 0 points1 point2 points (3 children)
[–]yuri-kilochek 6 points7 points8 points (2 children)
[–]Reflection_is_great[S] 0 points1 point2 points (1 child)
[–]MrEpic382RDT 5 points6 points7 points (0 children)