模板的分离方式

zl0606520 2008-04-03 02:30:52
#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这个关键字出问题了,请这个词该怎么用,谢谢!
...全文
100 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jieleiping 2008-04-03
  • 打赏
  • 举报
回复
可以分离

export可以

还有一种比较简单的办法


引用的时候同时引用.h和.cpp文件就没问题了
liveforme 2008-04-03
  • 打赏
  • 举报
回复
模板似乎都要写在一个.h里的
ttkk_2007 2008-04-03
  • 打赏
  • 举报
回复
这个关键字好像还不支持
你还是改成包含吧
jieao111 2008-04-03
  • 打赏
  • 举报
回复
听说没有支持的编译器--------
chai21cn 2008-04-03
  • 打赏
  • 举报
回复
模板的分离模式不好用,建议不使用
taodm 2008-04-03
  • 打赏
  • 举报
回复
不支持,不要用了。
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-03 02:30
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下