3 ms·
In C++, you can use templates to pattern match/duck type interfaces at compile time. So "template<typename PrincType> void princOk(PrincType& p, Stuff& stuff)
by CoolGuySteve 7y ago
In C++, you can use templates to pattern match/duck type interfaces at compile time.
So "template<typename PrincType> void princOk(PrincType& p, Stuff& stuff) {p.doThing(stuff); }" would map properly as long as doThing was implemented in all the different classes. You don't actually need an interface or base class for it to work.
The rest of the dynamic mapping is faster by calling switch() on an enum class member and than static_cast rather than relying on dynamic_cast.