TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24307 16
What is the most modern way to implement traits/multiple dispatch/multiple inheritance?

I am coming back to C++ after a few years of abstinence, and have since picked up on traits and multiple dispatch from Rust and Julia, and was hoping that there is an easy way to get the same in C++ as well.
Usually i have just written a single virtual parent class, and then i had a container of pointers onto children. This was ok for smaller use cases and did polymorphism fine, but it would fail if i would like to implement more interfaces/traits for my objects. I.e. i want to have shapes, several are movable, several others are also scalable, not all scalables are also movable.

What should i look into? I am pretty confused, since C++ does C++ things again, and there does not seem to be a single unified standard. There seems to be multiple inheritance, which i think would work, but i learned i should never ever ever do this, because of diamond inheritance.
Then there seem to be concepts, and type erasure. This seems to have a lot of boiler plate code (that i don't totally understand atm).

There also seems to be some difference between compile time polymorphism and run time polymorphism. I do not want to have to suddenly refactor something, just because i decide i need a vector of pointers for a trait/concept that previously was defined only in templates.

What would you use, what should i learn, what is the most future proof? Or is this a case of, you think you want this, but you don't really?

https://redd.it/1p353bp
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 12, 2026ACCU Overload Journal 195 - October 2026 https://accu.org/journals/overload/overload195 ht…
  2. Oct 12, 2026C++ Contracts C++ contracts are a good thing, why are people saying it's a bad thing? Anyb…
  3. Oct 11, 2026wxWidgets 3.2.12 and 3.3.4 Released https://wxwidgets.org/news/2026/10/wxwidgets-3.2.12-an…
  4. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
  5. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  6. Oct 10, 2026Yantra: an LALR(1) parser generator for C++23 Yantra: an LALR(1) parser generator for C++2…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →