c++ standard practice: virtual interface classes vs. templates

前端 未结 6 1208
梦如初夏
梦如初夏 2020-12-04 08:06

I have to make a decision regarding generalization vs polymorphism.

Well the scenario is standard: I want to make my monolithic interdependent code to be more modula

6条回答
  •  暖寄归人
    2020-12-04 08:31

    I use both in my large code base. When the type is known at compile time, I design it with templates, when it's known only at run time, I use virtual functions. I find the virtual functions easier to program and easier to read later, however there are times where performance is critical and the fact that the templated polymorphism (if you can really call it polymorphism) can be inlined really helps.

提交回复
热议问题