Dyamic vs Static Polymorphism in C++ : which is preferable?

前端 未结 4 1299
孤城傲影
孤城傲影 2020-12-25 14:44

I understand that dynamic/static polymorphism depends on the application design and requirements. However, is it advisable to ALWAYS choose static polymorphism over dynamic

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 14:49

    Static and dynamic polymorphism are designed to solve different problems, so there are rarely cases where both would be appropriate. In such cases, dynamic polymorphism will result in a more flexible and easier to manage design. But most of the time, the choice will be obvious, for other reasons.

    One rough categorisation of the two: virtual functions allow different implementations for a common interface; templates allow different interfaces for a common implementation.

提交回复
热议问题