c++ 中链栈初始化的问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 02:45:00
我要实现操作系统中的银行家算法,于是定义了一个Process类:
typedef class process
{
public:

string name;
int Oper[Resource]; //已分配
int Req[Resource]; //尚需求
int App[Resource]; //申请
int Str[Resource];
bool complete; //是否完成
int order; //安全检查算法中的完成顺序
int ResNum; //实际问题中涉及的资源个数
int Active; //是否为当前调度的进程
process *next; //指向该进程下一个进程的指针

process(); //默认构造函数
process(string name,int *Oper,int *Req,int *Str,int ResNum); //重载构造函数

void printOper();
void printReq();
void printStr();
void print();
void Init();

}LinkStackNode;//end of class process
typedef process LinkStackNode ;

下面我想要初始化这个链的头指针,于是这样写:
void process::Init()
{
LinkStackNode *temp;
temp=new LinkStackNode();
(*this)=temp;
this->next=null;
};

编译时提示错误:
c:\documents and settings\银

这种创建链表的方法有问题
这个类实例化时,它本身就成为了一个节点
称为链表的一部分
我觉得,你应该改为:
void process::Init()
{
LinkStackNode *temp;
temp=new LinkStackNode();
this->next=temp;
};
如果是第一个创建的话,它本身就为
这个链表的头