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
Post #24307
16