奇怪的0X1引起读取访问权限冲突

C++语言 码拜 8年前 (2016-06-07) 4507次浏览
我们都知道,在Debug生成中,会有0xcdcdcdcd ,0xdddddddd ,0xfeeefeee ,0xcccccccc ,0xabababab这种值引发的访问权限冲突。
但是,本人这次遇到一个问题,是0X1引起的访问权限冲突,本人苦思无解,特来求帮助各位高手。
先看错误图片:奇怪的0X1引起读取访问权限冲突
好的,错误大家看完了,本人就上代码:
main.cpp:
#include “head.h”
VOID EnListInit(Node *head)
{
int i = 0;
Node *p = head;
while (i < MAX_NODE_NUM)
{
i++;
p = new Node;
p->Data = rand() % 5;
p = p->Next;
}
p = new Node;
p->Data = rand() % 5;
p->Next = NULL;
}
VOID EnListAdd(Node *head)
{
Node *p = head;
while (p->Next != NULL)
{
p = p->Next;
}
p->Next = new Node;
p->Data = rand() % 5;
}
VOID EnListDel(Node *head)
{
Node *p = head;
Node *q = p->Next;
while (q != NULL)
{
if (!q->Data)
{
p->Next = q->Next;
delete q;
q = p->Next;
}
p = q;
q = p->Next;
}
}
VOID EnListUpd(Node *head)
{
Node *p = head;
while (p->Next != NULL)
{
std::cout << p->Data;
p = p->Next;
}
}
VOID EnListDestroy(Node *head)
{
Node *p = head;
while (p->Next != NULL)
{
delete p;
p = p->Next;
}
}
VOID Init(Node *head)
{
EnListInit(head);
}
VOID ShutDown(Node *head)
{
EnListDestroy(head);
}
int main(Node *head)
{
srand((unsigned)time(NULL));
Init(head);
EnListUpd(head);
EnListAdd(head);
EnListAdd(head); EnListAdd(head);
EnListUpd(head);
EnListDel(head);
EnListUpd(head);
EnListDestroy(head);
system(“pause”);
}
head.h:
#pragma once
#include <Windows.h>
#include <tchar.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#define MAX_NODE_NUM 10
struct Node
{
int Data;
Node *Next;
};
static struct Node *head = new Node;
这个错误困扰本人许久,希望大家帮本人解决。谢谢。
解决方案

50

int main(Node *head)
标准 main 函数
Node *head这个参数是 int argc
argc 最少为1
因此
head =0x01;
这就是你的程序出错的理由

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明奇怪的0X1引起读取访问权限冲突
喜欢 (1)
[1034331897@qq.com]
分享 (0)