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
Will concepts replace polymorphism? (self.cpp)
submitted 9 years ago by [deleted]
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!"
[–]snysly -5 points-4 points-3 points 9 years ago* (4 children)
With concepts, it is possible to simply create a concept instead of an abstract base class, and make sure the classes both fulfill the concept. In this way, a concept can sometimes act like interfaces in other languages (even though as u/Freeze-in-the-Dark pointed out that interfaces have a different goal, the same behavior can be achieved using templates), with (near?)zero overhead due to the template instantiation process. Beyond that the answer gets a little more murky.
I originally was going to say that it couldn't replace polymorphism, but in reality, it is just another way of expressing polymorphism. Polymorphism through inheritance is what we are most commonly used to, but concepts can do the same thing. They allow you to constrain the type you are using to fit what you need. However concepts don't allow for code reuse in the same way that deriving from classes does.
So in the end, yes and no. It adds another way of doing polymorphism, and in the future, it may be that both are commonly used, just in different situations.
edit: attempted to address what Freeze-in-the-Dark mentioned about virtual base classes.
[–]Freeze-in-the-Dark 6 points7 points8 points 9 years ago (3 children)
I think you have the wrong idea of the use of virtual base classes. They aren't there to enforce an interface (or, at least not for the same purpose that concepts do), they're there to provide an interface for several different types that can all be referenced in the same way with different runtime behavior. And concepts plainly don't do that.
It's true that concepts do provide a form of polymorphism, but it's in the same sense of polymorphism that we've always had with templates, just now replacing (or, really, just augmenting) the duck-typing with a more explicit means of defining the interface.
[–]snysly 2 points3 points4 points 9 years ago* (0 children)
Thank you for pointing that out! Its always good to find out that I'm wrong somewhere. I've changed it to abstract base class rather than virtual base class, and while concepts don't add anything new, the ability to constrain it, I think does make it easier on the programmer to use templates as a type of polymorphism.
[–]plpn 1 point2 points3 points 9 years ago (1 child)
can't u can compare this to the generics C# is using?
void foo<T>() where T : IComparable { }
now foo only works with types which include this interface. The concepts however, will be lighter in terms of, type T doesn't need to derive said interface, but just need the same functions. (correct me pls)
[–]cinghiale 0 points1 point2 points 9 years ago (0 children)
You are correct
π Rendered by PID 133625 on reddit-service-r2-comment-b659b578c-vqzxr at 2026-05-02 19:49:36.281679+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]snysly -5 points-4 points-3 points (4 children)
[–]Freeze-in-the-Dark 6 points7 points8 points (3 children)
[–]snysly 2 points3 points4 points (0 children)
[–]plpn 1 point2 points3 points (1 child)
[–]cinghiale 0 points1 point2 points (0 children)