//头文件
#pragma once
#include
#include
#include
template
class arry
{
public:
arry(int size = 4) {
m_arry = new LH[size];
m_size = size;
m_num = 0;
}
void pushnumber(LH n) {
if (m_num >= m_size ) {
change();
}
m_arry[m_num] = n;
m_num++;
}
void lprintf(int m){
cout << m_arry[m]<<endl;
}
~arry() {
delete[]m_arry;
cout << "析构函数";
}
private:
void change() {
int n_size = m_size + 4;
LH *n_arry = new LH[n_size];
memcpy(n_arry, m_arry, m_size);
delete[]m_arry;
m_arry = n_arry;
m_size = n_size;
}
private:
int m_size;
LH *m_arry;
int m_num;
};
//源文件----------------
#include"lin.h"
using namespace std;
int main(void) {
arry a;
for (int n=0; n < 8; n++) {
a.pushnumber(n);
a.lprintf(n);
}
cout << "-----------"<<endl;
for (int n = 0; n < 8 n++) {
a.lprintf(n);
}
system("pause");
return 0;
}
输出结果
0
1
2
3
4
5
6
7
0
-842150451
-842150451
-842150451
4
5
6
7