CRTP to avoid virtual member function overhead

前端 未结 4 1712
鱼传尺愫
鱼传尺愫 2021-02-11 03:01

In CRTP to avoid dynamic polymorphism, the following solution is proposed to avoid the overhead of virtual member functions and impose a specific interface:

temp         


        
4条回答
  •  忘了有多久
    2021-02-11 03:33

    The whole point of this pattern is, as far as I understand, that you can pass arguments simply as template base & and your interface is defined by (non-virtual) functions in base. If you don't have an interface that you want to define (as you are suggesting in the second part of your question), then there's no need for any of this in the first place.

    Note that you are not "imposing" an interface like with pure virtual functions, but rather you are providing an interface. Since everything is resolved at compile time, "imposing" isn't such a strong requirement.

提交回复
热议问题