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

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.

主站蜘蛛池模板: 扶风县| 汝南县| 阿鲁科尔沁旗| 兴海县| 固原市| 古田县| 平利县| 五大连池市| 中超| 沭阳县| 蓬溪县| 平山县| 桑植县| 昔阳县| 西乌珠穆沁旗| 涪陵区| 元阳县| 江城| 嘉荫县| 绥芬河市| 日照市| 菏泽市| 兴城市| 新绛县| 九龙城区| 乌鲁木齐县| 山西省| 玉田县| 上林县| 白城市| 昌江| 沅江市| 霍州市| 赤水市| 阜南县| 海晏县| 浦城县| 平遥县| 凤台县| 西昌市| 巨鹿县|