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

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.

主站蜘蛛池模板: 澎湖县| 浠水县| 新泰市| 桐乡市| 东丰县| 朝阳县| 方山县| 吐鲁番市| 武威市| 新龙县| 綦江县| 黑龙江省| 阆中市| 日照市| 云南省| 宜春市| 饶阳县| 沿河| 南昌县| 清水县| 南和县| 枝江市| 丹巴县| 浪卡子县| 厦门市| 内江市| 视频| 若尔盖县| 讷河市| 庆元县| 蕲春县| 五华县| 武宣县| 日喀则市| 临泽县| 蓬安县| 许昌市| 黎川县| 临颍县| 安吉县| 西城区|