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

C++链接有关问题

2012-03-15 
C++链接问题想写一个建立二叉树的类,只写了构造函数,编译就出现了以下问题:1BiTree.obj : error LNK2019:

C++链接问题
想写一个建立二叉树的类,只写了构造函数,编译就出现了以下问题:
1>BiTree.obj : error LNK2019: unresolved external symbol "public: struct tree * __thiscall biTree::create_btree(struct tree *,struct tree *,char)" (?create_btree@biTree@@QAEPAUtree@@PAU2@0D@Z) referenced in function "public: __thiscall biTree::biTree(char *,int)" (??0biTree@@QAE@PADH@Z)

全部编译结果如下:
1>------ Build started: Project: BiTree, Configuration: Debug Win32 ------
1>Compiling...
1>BiTree.cpp
1>g:\c++class\bitree\bitree.cpp(111) : warning C4715: 'create_btree' : not all control paths return a value
1>Linking...
1>BiTree.obj : error LNK2019: unresolved external symbol "public: struct tree * __thiscall biTree::create_btree(struct tree *,struct tree *,char)" (?create_btree@biTree@@QAEPAUtree@@PAU2@0D@Z) referenced in function "public: __thiscall biTree::biTree(char *,int)" (??0biTree@@QAE@PADH@Z)
1>G:\C++Class\BiTree\Debug\BiTree.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://g:\C++Class\BiTree\BiTree\Debug\BuildLog.htm"
1>BiTree - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
代码如下:

C/C++ code
#include<iostream>#include <string>#include<stdio.h>using namespace std;struct tree {                              char info;                               struct tree *left,*right;            };class biTree{public:    biTree(char *s, int n );    ~biTree();    struct tree *create_btree(struct tree *root,struct tree *r,char info);    void InOrder(struct tree *T);           //中序递归遍历二叉树    private:    struct tree  *root;};//******************************************// the main function //******************************************int main(){       return 0;}  biTree::biTree(char *a, int n ){                      root = '\0';           char *s;    s = a;    do {         s = a;        n--;                if (!root){            root=biTree::create_btree(root,root,*s);        }        else{            //create_btree(root,root,*s);        }        a++;      }  while ( n ) ;}struct tree biTree::*create_btree(struct tree *root,struct tree *r,char info){      if (r ==0 )    {        r=new (struct tree);        if ( r == 0)        {              printf("Out of memory\n");            return 0 ;        }        r->left= 0;        r->right=0;        r->info=info;        if (root)        {            if(info<root->info)    root -> left=r;            else   root->right=r;        }        else        {            r->right=0;            r->left = 0;        }    }        if (info < r->info)    create_btree(r,r->left,info);    if(info>=r->info)    create_btree(r,r->right,info);} 

网上找了,没找到解决办法.各位大哥帮忙看下,谢谢了!


[解决办法]
C/C++ code
struct tree* biTree::create_btree(struct tree *root,struct tree *r,char info)//*号写错地方了
[解决办法]
struct tree biTree::*create_btree(struct tree *root,struct tree *r,char info)
--------------------------------
struct tree* biTree::create_btree(struct tree *root,struct tree *r,char info)

[解决办法]
struct tree biTree::*create_btree(struct tree *root,struct tree *r,char info)
改为
struct tree* biTree::create_btree(struct tree *root,struct tree *r,char info)

热点排行