首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求教undefined reference to,该怎么解决

2012-06-28 
求教undefined reference to用g++编译一下代码时出现这样的问题:undefined reference to `Treeint::Tree

求教undefined reference to
用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 }
 

[解决办法]
Tree();
 19 virtual ~Tree();

这两个函数都没实现

热点排行