读书人

关于C++ 友元函数的小疑点

发布时间: 2012-08-25 10:06:20 作者: rapoo

关于C++ 友元函数的小问题
这个是我写的二叉树的程序 编译不成功 不知道什么问题
各位大大帮忙看下哈~~
谢谢了~~

#include<iostream>

using namespace std ;


class BinaryTreeNode{
friend void visit(BinaryTreeNode *) ;
friend class BinaryTree ;


public:
BinaryTreeNode(){ LeftChild = RightChild = 0 ; }
BinaryTreeNode(int e){ data = e ;}
BinaryTreeNode(int e ,BinaryTreeNode *l ,BinaryTreeNode *r){ data = e ;LeftChild = l ;RightChild = r ;}


private:
int data ;
BinaryTreeNode * LeftChild , * RightChild ;

}

void visit(BinaryTreeNode * b){
cout<<b->data<<endl ;
return ;
}


[解决办法]

C/C++ code
#include<iostream>using namespace std ;class BinaryTreeNode{friend void visit(BinaryTreeNode *) ;friend class BinaryTree ;public:BinaryTreeNode(){ LeftChild = RightChild = 0 ; }BinaryTreeNode(int e){ data = e ;}BinaryTreeNode(int e ,BinaryTreeNode *l ,BinaryTreeNode *r){ data = e ;LeftChild = l ;RightChild = r ;}private:int data ;BinaryTreeNode * LeftChild , * RightChild ;}
[解决办法]
跟你说了啊,掉了一个“;”
[解决办法]
#include<iostream>

using namespace std ;


class BinaryTreeNode{
friend void visit(BinaryTreeNode *) ;
friend class BinaryTree ;


public:
BinaryTreeNode(){ LeftChild = RightChild = 0 ; }
BinaryTreeNode(int e){ data = e ;}
BinaryTreeNode(int e ,BinaryTreeNode *l ,BinaryTreeNode *r){ data = e ;LeftChild = l ;RightChild = r ;}


private:
int data ;
BinaryTreeNode * LeftChild , * RightChild ;

};

void visit(BinaryTreeNode * b){
cout<<b->data<<endl ;
return ;
}

读书人网 >C++

热点推荐