template VS Inheritance

来源:互联网 发布:全球最贵的十大域名 编辑:程序博客网 时间:2024/06/06 17:55

It depends on whether the coupling can be be decided at compile time or must be delayed until runtime.

If the coupling between a component and its dependencies is decided permanently at compile time, you can use templates. The compiler will then be able to perform inlining.

If however the coupling needs to be decided at runtime(e.g. the user chooses which other component will supply the dependency, perhaps through a configuration file) then you can't use templates for that, andyou must use a runtime polymorphic mechanism.If so, your choices includevirtual functions, function pointers orstd::tr1::function
0 0