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

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

主站蜘蛛池模板: 沙河市| 龙岩市| 涞水县| 南汇区| 怀宁县| 广汉市| 赤城县| 深圳市| 板桥市| 班戈县| 绥芬河市| 临沧市| 定兴县| 嘉善县| 南江县| 冀州市| 阳谷县| 东源县| 景泰县| 朝阳市| 雅安市| 聂拉木县| 临夏市| 天水市| 普洱| 万安县| 周口市| 黄梅县| 玉林市| 自治县| 彭州市| 会同县| 浦北县| 平邑县| 塔河县| 宁化县| 东海县| 潜山县| 柯坪县| 桂平市| 太原市|