64,640
社区成员
发帖
与我相关
我的任务
分享
template<class T>
class List
{
protected:
int size;
public:
List():size(0){}
bool empty()
{
return size==0;
}
virtual void insert(T t,int position)=0;
};
template<class T>
class ArrayList:public List<T>
{
private:
int maxSize;
T* t;
public:
ArrayList(int initSize=20):maxSize(initSize)
{
t=new T[initSize];
}
void insert(T t,int position);
};
#include "test.h"
template<class T>
void ArrayList<T>::insert(int t,int position)
{
cout << "ArrayList" << endl;
} ;
#include "iostream"
#include "test.h"
using namespace std;
int main()
{
int a;
List<int> *l=new ArrayList<int>;
l->insert(a,5);
return 0;
}
#ifndef TEST_H
#define TEST_H
template<class T>
class List
{
protected:
int size;
public:
List():size(0){}
bool empty()
{
return size==0;
}
virtual void insert(T t,int position)=0;
};
template<class T>
class ArrayList:public List<T>
{
private:
int maxSize;
T* t;
public:
ArrayList(int initSize=20):maxSize(initSize)
{
t=new T[initSize];
}
void insert(T t,int position);
};
#include "test.cpp" //包含cpp文件
#endif //TEST_H
#ifndef TEST_CPP
#define TEST_CPP
#include "test.h"
template<class T>
void ArrayList<T>::insert(T t,int position)//这里是T
{
cout << "ArrayList" << endl;
} ;
#endif //TEST_CPP
#include "iostream"
#include "test.h"
using namespace std;
int main()
{
int a=0;//初始化!!!
List<int> *l=new ArrayList<int>;
l->insert(a,5);
return 0;
}