求助高手 以下c++代码哪里有问题

来源:百度知道 编辑:UC知道 时间:2024/06/15 17:10:44
抱歉我太菜了,只是这样的代码编译不通过,我也不知道哪里错了。。。
Block.h:
#ifndef _BLOCK_
#define _BLOCK_

#include "Node.h"

class Block
{
private:
int Number;
Node *Next;
public:
Block();
void SetNum(int);
int GetNum();
void SetNext(Node *);
Node* GetNext();
};

#endif

Block.cpp:
#include <iostream>
#include <stdlib.h>
#include "Block.h"

using namespace std;

Block::Block()
{
Number = -1;
Next = NULL;
}

void Block::SetNum(int Num)
{
Number = Num;
}

int Block::GetNum()
{
return Number;
}

void Block::SetNext(Node *n)
{
Next = (Node *)malloc(sizeof(Node *));
if(Next = NULL)
cout<<"new node out of space!"<<endl;
else
Next = n;
}

Node* Block::GetNext()
{
return Next;<

在文件Node.h中,类Node定义中语句
Block *BList;
存在标记Block无效。原因是头文件嵌套调用:
在文件Node.h中包含了文件Block.h,然后文件Block.h又包含了文件Node.h。此时,第二个包含的Node.h中定义Block *BList;时,无法找到Block的定义。
建议将Block.h中的指令
#include "Node.h"
修改为
class Node;
即外部声明一下类Node。

1.“}”后面不能加“;”

对“}”后面不能加“;” 是java,c++里要加;