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

大侠们来解释下VC++6.0编译过不去的原因可以吗?该如何处理

2012-03-07 
大侠们来解释下VC++6.0编译过不去的原因可以吗?C/C++ code#includestdio.h#includestdlib.h#define NU

大侠们来解释下VC++6.0编译过不去的原因可以吗?

C/C++ code
#include<stdio.h>#include<stdlib.h>#define NULL 0typedef char type;typedef struct node{    type date;    int ltag,rtag;    struct node *lchild,*rchild;}node,*tree;tree pre;tree greetree()///////////////////////建立2叉树{    type x;    tree bt;    scanf("%c",&x);    getchar();    if(x=='0')    {                bt=NULL;    }    else    {        bt=(tree)malloc(sizeof(node));        bt->date=x;        bt->lchild=greetree();        bt->rchild=greetree();    }    return bt;}preeorder(tree T)///////////线索化{    tree thrt;    thrt=(tree)malloc(sizeof(node));    thrt->ltag=0;thrt->rtag=1;thrt->rchild=thrt;    if(!T)        thrt->lchild=thrt;    else    {        thrt->lchild=T;pre=thrt;        preethreading(T);        printf("xx\n");        pre->rchild=thrt;        pre->rtag=1;        thrt->rchild=pre;    }} preethreading(tree p)/////////////////接上{    if(p)    {   preethreading(p->lchild);        if(!p->lchild)        {            p->ltag=1;p->lchild=pre;}        else p->ltag=0;        if(!pre->rchild)        {            pre->rtag=1;            pre->rchild=p;}        else p->rtag=0;        pre=p;        if(p->ltag==0)            preethreading(p->lchild);         preethreading(p->rchild);             }    }main(){    tree s;    s=greetree();    preeorder(s);    }

这个程序在VC++6.0创建C++的话编译过不去,但是创建C/C++的话编译就过得去。这个程序是C写的,但是C++的语法限制比C要严格很多可以检查C多很多未知错误。

2叉树的线索化函数有问题, preethreading(T);函数,线索化有的2叉树没问题,线索化有的2叉树,preethreading(T);运行完后就中止了。




[解决办法]
C/C++ code
#include<stdio.h>#include<stdlib.h>#define NULL 0typedef char type;typedef struct node{    type date;    int ltag,rtag;    struct node *lchild,*rchild;}node,*tree;tree pre;tree greetree()///////////////////////建立2叉树{    type x;    tree bt;    scanf("%c",&x);    getchar();    if(x=='0')    {                bt=NULL;    }    else    {        bt=(tree)malloc(sizeof(node));        bt->date=x;        bt->lchild=greetree();        bt->rchild=greetree();    }    return bt;}preethreading(tree p)/////////////////接上{    if(p)    {         if(!p->lchild)        {            p->ltag=1;p->lchild=pre;}        else p->ltag=0;        if(!pre->rchild)        {            pre->rtag=1;            pre->rchild=p;}        else p->rtag=0;        pre=p;        if(p->ltag==0)            preethreading(p->lchild);         preethreading(p->rchild);             }    }preeorder(tree T)///////////线索化{    tree thrt;    thrt=(tree)malloc(sizeof(node));    thrt->ltag=0;thrt->rtag=1;thrt->rchild=thrt;    if(!T)        thrt->lchild=thrt;    else    {        thrt->lchild=T;pre=thrt;        preethreading(T);        printf("xx\n");        pre->rchild=thrt;        pre->rtag=1;        thrt->rchild=pre;    }}void main(){    tree s;    s=greetree();    preeorder(s);    }
[解决办法]
1、你的函数都没有返回值,严格来讲是错的

2、虽然写在main()前面不需要声明了,可是你存在这函数之间的调用啊,也就是说,在第一个函数里面调用了第三

个,可是第三个那个时候还没定义呢,所以会报错...

建议还是写函数声明吧,按规矩做事。虽然语法那样规定,但是世纪中很少那样写,原因很简单,基于“接口与实现

分离”的原则,函数声明都是放在头文件中的!

热点排行