Get the App
SLTechnology News&Howtos  ›  Development  › 

What is C++ generic programming?

Shulou Source: shulou.com Published: 2022-06-03 05:05:57 10月25日 Update

In this issue, the editor will bring you about what C++ generic programming is. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Generic programming has the same goal as object-oriented programming, even though techniques for reusing code and abstracting common concepts are simpler. But object-oriented programming emphasizes the data aspect of programming, while generic programming emphasizes independence from specific data types.

This paper introduces another branch of C++ programming, which is juxtaposed with object-oriented programming-generic programming, mainly introducing three parts: function template, class template and member template.

Generic programming

Template is an important idea of generic programming. STL (Standard Template Library, Standard template Library) is an example function template implemented by template.

Compared with function overloading (functions with the same name but different parameter lists in the same scope), the function template only needs one function to realize part of the function overloading (the same number of parameters is of different types. Function overloading requires the definition of multiple functions with different parameter lists with the same name)

Template / / you can also write template where class and typename have the same function as void tfunc (T & t, Y & y) {cout

Tags: Templates functions parameters types programming subclasses normal objects parts tests data same instances members results processing running clocking different polymorphic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Shulou Tech Info MariaDB Redmi