VC++ error C2664

问题描述
error C2664: ‘CreateBiTree’ : cannot convert parameter 1 from 'struct BiTnode ** ’ to 'struct BiTNode ** ’
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

代码

// 实验三.cpp : Defines the entry point for the console application.
//

#include<stdafx.h>
#include"stdio.h"
#include"stdlib.h"
typedef char TElemType;
typedef struct BiTNode
{
    
    
	TElemType data;
	struct BiTnode *lchild,*rchild;
}BiTNode,*BiTree;

void  CreateBiTree(BiTree *T)
{
    
    
	TElemType ch;
	scanf("%c",&ch);
	if(ch==' ')
		*T=NULL;
	else
	{
    
    
		*T=(BiTree)malloc(sizeof(BiTNode));
			if(!*T)
				exit(-1);
			(*T)->data=ch;
			CreateBiTree(&(*T)->lchild);
			CreateBiTree(&(*T)->rchild);
	}
}

void DestroyBiTree(BiTree *T)
{
    
    
	if(*T)
	{
    
    
		if((*T)->lchild )
			DestroyBiTree(&((*T)->lchild));
		if((*T)->rchild )
			DestroyBiTree(&((*T)->rchild));
		free(*T);
		*T=NULL;
	}
}

void PreOrderTraverse(BiTree T)
{
    
    
	if(T)
	{
    
    
		printf("%c",T->data);
		PreOrderTraverse(T->lchild);
		PreOrderTraverse(T->rchild);
	}
}

void InOrderTraverse(BiTree T)
{
    
    
	if(T)
	{
    
    
		InOrderTraverse(T->lchild);
		printf("%c",T->data);
		InOrderTraverse(T->rchild);
	}
}

void PostOrderTraverse(BiTree T)
{
    
    
	if(T)
	{
    
    
		PostOrderTraverse(T->lchild);
		PostOrderTraverse(T->rchild);
		printf("%c",T->rchild );

	}
}

int main()
{
    
    
	BiTree T;
	printf("请输入建立二叉树的字符序列(包括空格):\n");
	CreateBiTree(&T);
	printf("\n先序递归遍历二叉树:\n");
	PreOrderTraverse(T);
	printf("\n中序递归遍历二叉树:\n");
	InOrderTraverse(T);
	printf("\n后序递归遍历二叉树:\n");
	PostOrderTraverse(T);
	printf("\n");
	DestroyBiTree(&T);
	return 0;
}

错误

D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(26) : error C2664: 'CreateBiTree' : cannot convert parameter 1 from 'struct BiTnode ** ' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(27) : error C2664: 'CreateBiTree' : cannot convert parameter 1 from 'struct BiTnode ** ' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(36) : error C2664: 'DestroyBiTree' : cannot convert parameter 1 from 'struct BiTnode ** ' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(38) : error C2664: 'DestroyBiTree' : cannot convert parameter 1 from 'struct BiTnode ** ' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(49) : error C2664: 'PreOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(50) : error C2664: 'PreOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(58) : error C2664: 'InOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(60) : error C2664: 'InOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(68) : error C2664: 'PostOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\计算机学习的所有东西\数据结构\数据结构实验代码运行文件\实验三\实验三.cpp(69) : error C2664: 'PostOrderTraverse' : cannot convert parameter 1 from 'struct BiTnode *' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.

原因分析
struct BiTnode ** ' to 'struct BiTNode
把BiTNode写成了BiTnode

解决方案

typedef struct BiTNode
{
    
    
	TElemType data;
	struct BiTnode *lchild,*rchild;//把BiTnode改为BiTnode即可
}BiTNode,*BiTree;

第四行中把BiTnode改为BiTnode即可

猜你喜欢

转载自blog.csdn.net/qq_45876838/article/details/109320345
今日推荐