-3

https://github.com/apache/mesos/blob/master/include/mesos/module.hpp#L56

The mesos modules all derive from the struct ModuleBase, and when create different module instances they use template. I am curious about that, why they prefer template than heritage? Is that because of running time speed?

I also have noticed that so many open source projects in C++ prefer to use a lot of template which cause the code hard to read and understand, why?

Liu Weibo
  • 434
  • 5
  • 16

1 Answers1

1

It seems that there are some general discuss maybe help to someone who are here later:

When should I use templates instead of inheritance, and vice versa?

When to use template vs inheritance

http://www.gotw.ca/publications/mill06.htm

http://people.cs.uchicago.edu/~jacobm/pubs/templates.html

template is faster than inheritance since it choose the right function to be called at the compiling time rather than at running time.

also they have very similar function that they both support interfaces and polymorphism.

Community
  • 1
  • 1
Liu Weibo
  • 434
  • 5
  • 16