- 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.
推薦閱讀
- Apache ZooKeeper Essentials
- Docker技術(shù)入門(mén)與實(shí)戰(zhàn)(第3版)
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計(jì)
- Python數(shù)據(jù)可視化:基于Bokeh的可視化繪圖
- Internet of Things with Intel Galileo
- 自然語(yǔ)言處理Python進(jìn)階
- Elasticsearch Server(Third Edition)
- 單片機(jī)應(yīng)用與調(diào)試項(xiàng)目教程(C語(yǔ)言版)
- Creating Mobile Apps with jQuery Mobile(Second Edition)
- Python項(xiàng)目實(shí)戰(zhàn)從入門(mén)到精通
- Orleans:構(gòu)建高性能分布式Actor服務(wù)
- AMP:Building Accelerated Mobile Pages
- Java高手是怎樣煉成的:原理、方法與實(shí)踐
- Wearable:Tech Projects with the Raspberry Pi Zero
- Java 11 and 12:New Features