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

  • 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.

主站蜘蛛池模板: 济宁市| 宝应县| 西充县| 兴城市| 高要市| 福鼎市| 沁源县| 双峰县| 肇庆市| 星子县| 衡东县| 石屏县| 介休市| 临沭县| 南京市| 岳普湖县| 吉木萨尔县| 万山特区| 都兰县| 白银市| 大冶市| 莲花县| 柳州市| 乐安县| 屯留县| 左权县| 同心县| 富源县| 龙泉市| 晋城| 龙口市| 嘉禾县| 禄丰县| 漳州市| 庄浪县| 福安市| 广汉市| 新竹市| 页游| 丰原市| 建水县|