官术网_书友最值得收藏!

Class templates

A class template defines a family of classes, and it is often used to implement a container. For example, the C++ Standard Library contains many class templates, such as std::vector, std::map, std::deque, and so on. In OpenCV, cv::Mat is a very powerful class template and it can handle 1D, 2D, and 3D matrices or images with built-in data types such as int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double, and so on.

Similar to function templates, as shown in the following diagram, the concept of class templates contains a template creation syntax, its specialization, and its implicit and explicit instantiations:

In part I of the preceding diagram, with a certain syntax format, we can create a class template for generic types, also known as a primary template, and it can be customized for special types with different member functions and/or variables. Once we have a class template, in part II, the compiler will instantiate it to template classes either explicitly or implicitly based on the application's demand.

Now, let's look at the syntax for creating a class template.

主站蜘蛛池模板: 南宁市| 大同县| 周宁县| 德兴市| 普兰县| 金华市| 札达县| 临洮县| 华阴市| 镇安县| 资中县| 白水县| 库车县| 罗城| 桐城市| 江津市| 昭通市| 加查县| 炉霍县| 易门县| 修文县| 修文县| 汨罗市| 讷河市| 河西区| 平顶山市| 平武县| 五指山市| 安乡县| 虎林市| 凤庆县| 烟台市| 辛集市| 云阳县| 霍林郭勒市| 霍林郭勒市| 正安县| 安图县| 南川市| 贵阳市| 沾化县|