一个类成员函数的定义声明问题+++++

Dstnoe 2011-05-01 12:18:29

class AVL_Tree
{
typedef int KEY;
private:
struct TNode
{
TNode * parent;
TNode * left;
TNode * right;
int height;
KEY key;

};

TNode * Troot;

public:

AVL_Tree();

TNode * Find(KEY,TNode *&);


// ~AVL_Tree();


};

TNode* AVL_Tree::Find(KEY Ckey,TNode* &root)// <----- 提示此处错误!
{

if(root==NULL) cout<<"con't find the element:"<<Ckey<<endl;
if(root->key == Ckey) return root;
AVL_Tree::Find(Ckey,root->left);
AVL_Tree::Find(Ckey,root->right);


}


error: expected constructor, destructor, or type conversion before '*' token

问一下 我的函数定义 和 声明 哪里错了?
...全文
102 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmu_才盛 2011-05-01
  • 打赏
  • 举报
回复
struct TNode
{
TNode * parent;
TNode * left;
TNode * right;
int height;
KEY key;

};
这个定义就错了。。
typedef struct _TNode
{
struct _TNode * parent;
struct _TNode * left;
struct _TNode * right;
int height;
KEY key;
}TNode;
这样就行了。。
Dstnoe 2011-05-01
  • 打赏
  • 举报
回复
哦 ,明白!
机智的呆呆 2011-05-01
  • 打赏
  • 举报
回复

AVL_Tree::TNode* AVL_Tree::Find(KEY Ckey,TNode* &root)// <----- 提示此处错误!
{

if(root==NULL) cout<<"con't find the element:"<<Ckey<<endl;
if(root->key == Ckey) return root;
AVL_Tree::Find(Ckey,root->left);
AVL_Tree::Find(Ckey,root->right);


}
Dstnoe 2011-05-01
  • 打赏
  • 举报
回复
我的 成员函数声明如下:

TNode * Find(KEY,TNode * &);
机智的呆呆 2011-05-01
  • 打赏
  • 举报
回复
TNode是个AVL_Tree内部类,需要加作用域限定符AVL_Tree::TNode
無_1024 2011-05-01
  • 打赏
  • 举报
回复

TNode* AVL_Tree::Find(KEY Ckey,TNode &root)// <----- 提示此处错误!
{

if(root==NULL) cout<<"con't find the element:"<<Ckey<<endl;
if(root.key == Ckey) return root;
AVL_Tree::Find(Ckey,root.left);
AVL_Tree::Find(Ckey,root.right);


}

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧