模板的分离方式
#ifndef TLIST
#define TLIST
#include<iostream>
using namespace std;
tlist.h
template<typename T>
struct Node{
Node(T &d):c(d),next(0),pref(0){}
T c;
Node *next ,*pref;
};
export template<typename T>
class List{
Node<T>*first,*last;
public:
List();
void add(T &c);
void remove(T &c);
Node<T>*find(T &c);
void print();
~List();
};
#endif
tlist.cpp
#include"tlist.h"
export template<typename T>
List<T>::List():first(0),last(0){}
export template<typename T>
void List<T>::add(T &n)
{
Node<T>*p=new Node<T>(n);
p->next=first;first=p;
(last?p->next->pref:last)=p;
}
export template<typename T>
void List<T>::remove(T &n)
{
if(!(Node<T>*p=find(n)))return;
(p->next?p->next->pref:last)=p->pref;
(p->pref?p->pref->next:first)=p->next;
delete p;
}
export template<typename T>
Node<T>*List<T>::find(T &n)
{
for(Node<T>*p=first;p;p=p->next)
if(p->c==n)return p;
return 0;
}
export template<typename T>
List<T>::~List()
{
for(Node<T>*p;p=first;delete p)
first=first->next;
}
export template<typename T>
void List<T>::print()
{
for(Node<T>*p=first;p;p=p->next)
cout<<p->c<<" ";
cout<<'\n';
}
编译通过不了,export这个关键字出问题了,请这个词该怎么用,谢谢!