问题描述
- 怎样用DEV~C++在.cpp文件中插入一个.c文件,用在.cpp的头文件中去
-
.cpp文件:
#include
#include
using namespace std;int main()
{
template m;
m.CreateList(10);
for(int i = 0; i < length; i++)
cout << elem[i] << " ";
cout << endl;
m.Insert(2, 7);
for(int i = 0; i < length; i++)
cout << elem[i] << " ";
cout << endl;
return 0;
}要插入的.c文件:
#ifndef aaa.h
#define aaa.h
templateclass SQList
{
private:
T *elem;
int length;
int listsize;
public:
SQList(int m);
~SQList();
void CreateList(int n);
void Insert(int i, T e);
};
template
SQList::SQList(int m)
{
elem = new T[m];
if(!elem) throw "内存分配失败!";
length = 0;
listsize = m;
}
template
SQList::~SQList()
{
delete[] elem;
length = 0;
listsize = 0;
}
template
void SQList::CreateList(int n)
{
for(int i = 1; i <= n; i++)
elem[i - 0] = i;
}template
void SQList::Insert(int i, T e)
{
if(length >= listsize) throw "上溢!";
if(i < 1 || i > length + 1) throw "插入位置异常!";
for(j = length; j >= i; j--)
elem[j] = elem[j - 1];
elem[i - 1] = e;
length++;
}