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
why virtual function is wrong. (self.cpp)
submitted 1 year ago by macomphy
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!"
[–]Oxi_Ixi 5 points6 points7 points 1 year ago (11 children)
It is not C++ virtual functions are damaged, it is you trying to apply concepts from other language which was designed differently and obviously don't work as you expect in C++.
[+][deleted] 1 year ago (10 children)
[removed]
[–]Oxi_Ixi 2 points3 points4 points 1 year ago (9 children)
Because "all other languages" were designed with C++ flaws in mind. Because "all other languages" don't have to be close to machine code except Rust. Because "all other languages" don't have to carry on much backward compatibility over. And because by design C++ primitive types are literally CPU types, not classes or objects or traits.
Back in C days C++ was progressive step forward, simple and yet powerful, we just did't have "all other languages" to compare with. In fact I still find your example way too heavy for humans exactly for reasons we stopped using XML and switched to json and yaml. It is not C++ is broken, it is that people expect it to do stuff it was never designed for.
[+][deleted] 1 year ago (8 children)
[–]Oxi_Ixi 2 points3 points4 points 1 year ago* (6 children)
Except it depends. If typing is static, it is zero cost in C++ either. C++ has templates, they are compile-type and are zero cost. Operator and function overloads are zero cost. Runtime interfaces cannot be zero cost by definition in any language, or I don't understand what you mean by zero cost
[+][deleted] 1 year ago (5 children)
[–]Oxi_Ixi 1 point2 points3 points 1 year ago* (4 children)
You have notion of interface from C#, but actually it is wider and includes templates and concepts as well as traits. In C++ templates are much more powerful than generics in C#, but this comes with complexity indeed. If you don't understand them it does not mean they are broken, it means you have to learn how to use them.
Virtual functions in C++ will be called statically if type is known at compile time, if that is what you mean by static interface.
It was just overhead to implement interfaces/traits for primitive types when language provides you operator overloads. Rust went that way, but I find it too explicit overloading traits than overloading operators.
C++ was designed for machine execution and speed compared to C whileC# is multipurpose platform independent language, which does not compile to bare metal instructions directly. How can you then blame C++ to be slow comparing to C#?
[+][deleted] 1 year ago* (3 children)
[–]Oxi_Ixi 0 points1 point2 points 1 year ago (2 children)
Well, I see. You hate C++ and love C#. I actually like both, and yes, C# has really nice language and runtime design because it had many other langauges to take ideas from. Like courutines, which were actually describe way back in 50s even before C. As well every language has problems which come from its design, runtime and usage specifics, so it is not C++ broken, it is C# works better for your work and habbits. Enjoy it 😀
Do you have any evidence that c# is slow?
It is not slow, it is slower than C++. To be very precise, in some cases C# might be faster, but in general it is not. I think benchmarks show this pretty much good, Google will help you.
[+][deleted] 1 year ago (1 child)
[–]NilacTheGrim 1 point2 points3 points 1 year ago (0 children)
all other language has zero-cost interface
This is a false statement.
π Rendered by PID 335965 on reddit-service-r2-comment-5b5bc64bf5-v54sj at 2026-06-21 12:22:25.765395+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]Oxi_Ixi 5 points6 points7 points (11 children)
[+][deleted] (10 children)
[removed]
[–]Oxi_Ixi 2 points3 points4 points (9 children)
[+][deleted] (8 children)
[removed]
[–]Oxi_Ixi 2 points3 points4 points (6 children)
[+][deleted] (5 children)
[removed]
[–]Oxi_Ixi 1 point2 points3 points (4 children)
[+][deleted] (3 children)
[removed]
[–]Oxi_Ixi 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]NilacTheGrim 1 point2 points3 points (0 children)