求教undefined reference to

happypetersun 2012-05-08 10:19:27
用g++编译一下代码时出现这样的问题:
undefined reference to `Tree<int>::Tree()'

1 #include <stdlib.h>
2 #include <iostream>
3 using namespace std;
4
5 template <typename T>
6 struct CSTnode
7 {
8 T data;
9 struct CSTnode* firstchild;
10 struct CSTnode* nextsibling;
11 struct CSTnode* parent;
12 };
13
14 template <class T>
15 class Tree
16 {
17 public:
18 Tree();
19 virtual ~Tree();
20 virtual void getParent() const=0;
21 virtual void getFirstChild() const=0;
22
23 };
24
25 template <class T>
26 class csTree: public Tree<T>
27 {
28 public:
29 csTree();
30 ~csTree();
31 void getParent() const;
32 void getFirstChild() const;
33
34 private:
35 struct CSTnode<T>* root;
36 };
37
38 template <class T>
39 csTree<T>::csTree():Tree<T>()
40 {
41 root=new CSTnode<T>;
42 root->firstchild=NULL;
43 root->nextsibling=NULL;
44 }
45
46 template <class T>
47 csTree<T>::~csTree()
48 {
49 }
50 template <class T>
51 void csTree<T>::getParent() const
52 {
53 cout<<""<<endl;
54 }
55 template <class T>
56 void csTree<T>::getFirstChild() const
57 {
58 cout<<""<<endl;
59 }
60
61
62 int main()
63
64 {
65 csTree<int> cs;
66 return 1;
67 }
...全文
167 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2012-05-09
  • 打赏
  • 举报
回复
提示是未定义的行为……
ouyh12345 2012-05-09
  • 打赏
  • 举报
回复
Tree();
19 virtual ~Tree();

这两个函数都没实现
happypetersun 2012-05-09
  • 打赏
  • 举报
回复
各位能说得具体点吗?
xuzhuo 2012-05-09
  • 打赏
  • 举报
回复
没找到定义

64,654

社区成员

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

试试用AI创作助手写篇文章吧