关于C++ 友元函数的小疑点
关于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 ;
}
------解决方案--------------------
这个是我写的二叉树的程序 编译不成功 不知道什么问题
各位大大帮忙看下哈~~
谢谢了~~
#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 ;
}