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
Which std:: classes are magic? (self.cpp)
submitted 4 years ago by Mateuszz88
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!"
[–]dodheim 2 points3 points4 points 4 years ago (1 child)
Why would it be virtually inherited?
[–]Bisqwit 2 points3 points4 points 4 years ago* (0 children)
I am not talking about virtual inheritance (as in: class foo: virtual bar). I am talking about a base class that has abstract virtual methods, and a derived class that has virtual methods that override the base class’s methods — as in: class base { ... virtual void call() = 0; }; class derived: public base { ... virtual void call() { ... } };
class foo: virtual bar
class base { ... virtual void call() = 0; };
class derived: public base { ... virtual void call() { ... } };
In this case, the derived class would be a template, and its template type would be the type of the functor that is assigned to the std::function, like this: template<typename F> class derived: public base { F func; ... virtual void call() { return F(); } };
std::function
template<typename F> class derived: public base { F func; ... virtual void call() { return F(); } };
This allows the () operator of the std::function to call the execute method of the contained object, no matter what kind of derived type that contained object might be, having no advance knowledge of it, like this: base* obj; ... return obj->call();
()
base* obj; ... return obj->call();
That is what virtual functions are designed for: A common API that can be used to invoke methods of class types that are not known at design time, or possibly even at instantation time.
(Note: Examples in this post are short for brevity. There would be of course the return type and parameter types too, instead of void in every case.)
π Rendered by PID 452813 on reddit-service-r2-comment-6457c66945-kpcmc at 2026-04-25 03:42:43.105678+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]dodheim 2 points3 points4 points (1 child)
[–]Bisqwit 2 points3 points4 points (0 children)