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

  • Expert C++
  • Vardan Grigoryan Shunguang Wu
  • 182字
  • 2021-06-24 16:34:06

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.

主站蜘蛛池模板: 怀宁县| 佛学| 三明市| 喀什市| 北辰区| 盘山县| 垣曲县| 滨海县| 桦甸市| 洛浦县| 甘孜县| 三台县| 登封市| 大新县| 正镶白旗| 黄大仙区| 习水县| 靖安县| 临洮县| 金沙县| 新野县| 新乐市| 白沙| 普格县| 绥化市| 巴马| 东兴市| 区。| 新密市| 云浮市| 乐亭县| 随州市| 酉阳| 固安县| 会同县| 越西县| 德令哈市| 南京市| 西乌珠穆沁旗| 榆中县| 曲阳县|