Evaluation Issues in Generic Programming with Inheritance and Templates in C++
暂无分享,去创建一个
Abstract Generic Programming is a concept and style of programming that increases the correctness and reusability of the source code. In this paper, we draw upon our experience and the experience of other researchers in this field to discuss the advantages and disadvantages of the two major models of generic programming - inheritance and templates. This article reveals some practical cases when the use of the two models is appropriate and when not recommended. Finally, the article concludes with an example of natural coexistence of the two models and demonstrates how they can complement each other. Keywords : Generic Programming, Templates, Inheritance, OOP, Class, Function 1. Introduction Writing generic code is related to making the code reusable and clear, hence it improves the programming efficiency. In C++, there are two major programming models that allow code reuse . Code reuse is possible through inheritance and templates . The main difference lies in how the reuse happens. Whereas in inheritance the code reuse happens across inherited classes, in templates we have a sort of macro substitution of the type name to generate code for that type name. Whereas the main policy provided by inheritance is that the class’ methods (also called
[1] Rune B. Lyngsø,et al. Lecture Notes I , 2008 .
[2] Herb Sutter. Why not specialize function templates , 2001 .
[3] Bjarne Stroustrup,et al. Multiple Inheritance for C++ , 1989, Comput. Syst..
[4] Thomas K. Moore. Software development in C , 1988, SGCS.