- 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.
推薦閱讀
- Advanced Quantitative Finance with C++
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- Building a Game with Unity and Blender
- Oracle從新手到高手
- 編寫高質量代碼:改善Python程序的91個建議
- Spring Boot企業級項目開發實戰
- 數據結構與算法分析(C++語言版)
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- Programming Microsoft Dynamics? NAV 2015
- 計算機應用技能實訓教程
- Java7程序設計入門經典
- ROS機器人編程實戰
- 3D Printing Designs:The Sun Puzzle
- ASP.NET Core and Angular 2
- Implementing Domain:Specific Languages with Xtext and Xtend