- Expert C++
- Vardan Grigoryan Shunguang Wu
- 105字
- 2021-06-24 16:34:07
Instantiation
Considering the class template, V, we defined in the previous section, we'll assume the following declarations appear later:
V<char> cV;
V<int> iV(10);
V<float> fV(5);
Then, the compiler will create three instances of the V class, as follows:
class V<char>{
public:
V(int n=0);
// ...
public:
int m_nEle;
char *m_buf;
};
class V<int>{
public:
V(int n=0);
// ...
public:
int m_nEle;
int *m_buf;
};
class V<float>{
public:
V(int n = 0);
// ...
public:
int m_nEle;
float *m_buf;
};
Similar to function template instantiation, there are two forms of class template instantiation – explicit instantiation and implicit instantiation. Let's take a look at them.
推薦閱讀
- Functional Python Programming
- JavaScript百煉成仙
- Java程序設計實戰教程
- 案例式C語言程序設計
- Computer Vision for the Web
- Raspberry Pi for Secret Agents(Third Edition)
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- Learning Zurb Foundation
- Expert Data Visualization
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- 速學Python:程序設計從入門到進階
- JavaScript動態網頁編程
- 深入實踐Kotlin元編程
- OpenCV 3計算機視覺:Python語言實現(原書第2版)
- C語言程序設計