栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++,引发了异常: 读取访问权限冲突。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++,引发了异常: 读取访问权限冲突。

调试时遇到的问题;

原代码
#include
#include
#include
using namespace std;
class car
{
	string chepaihao;
	double arrive_time;//到达的时间
public:
	time_t start, end;
	int zi_weizhi;//自己的位置
	car(string p);//到达时间赋0
	static int weizhi;//总共位置
	car* next;
	string REchepaihao();//返回车牌号
	void getchepai(string p);//赋值车牌号
	int left_time();
};
int car::weizhi = 0;

car* t_top;//另一个链表的头指针;
void reading(car*&);
void push(car*& top1, car* now)
{
	if (top1 == NULL)
	{
		top1 = now;
		top1->next = NULL;
	}
	else
	{
		now->next = top1;
		top1 = now;
	}
	//cout << now->REchepaihao() << "已进入停车位" << endl;
}
void pop(car*&top)
{
	car* p = top;
	top = top->next;
	delete p;
	cout <REchepaihao()<< "您已开出停车场或为他人让位"<next)
		cout << index->REchepaihao() << endl;
}
car::car(string p)
{
	chepaihao = p;
	weizhi++;
	zi_weizhi = weizhi;
	//double cost;
	time(&start);
	//sleep(1);
	//time(&end);
	//cost = difftime(end, start);
	//printf("%f/n", cost);
	arrive_time = 0;
	next = NULL;
}
string car::REchepaihao()
{
	return chepaihao;
}

void car::getchepai(string p)
{
	chepaihao = p;
}

int car::left_time()
{
	return 0;
}

void reading(car*&top)
{
	string a[2] = { "YOVGYC98","UIRBP09" };
	for (int i = 0;i < 2;i++)
	{
		car* index = new car(a[i]);
		push(top, index);//这里出了问题;
	}

}

问题出在未初始化头指针 调试时问题截图

加入

top = new car(“YUILKVG78”);

正确代码
#include
#include
#include
using namespace std;
class car
{
	string chepaihao;
	double arrive_time;//到达的时间
public:
	time_t start, end;
	int zi_weizhi;//自己的位置
	car(string p);//到达时间赋0
	static int weizhi;//总共位置
	car* next;
	string REchepaihao();//返回车牌号
	void getchepai(string p);//赋值车牌号
	int left_time();
};
int car::weizhi = 0;

car* t_top;//另一个链表的头指针;
void reading(car*&);
void push(car*& top1, car* now)
{
	if (top1 == NULL)
	{
		top1 = now;
		top1->next = NULL;
	}
	else
	{
		now->next = top1;
		top1 = now;
	}
	//cout << now->REchepaihao() << "已进入停车位" << endl;
}
void pop(car*&top)
{
	car* p = top;
	top = top->next;
	delete p;
	cout <REchepaihao()<< "您已开出停车场或为他人让位"<next)
		cout << index->REchepaihao() << endl;
}
car::car(string p)
{
	chepaihao = p;
	weizhi++;
	zi_weizhi = weizhi;
	//double cost;
	time(&start);
	//sleep(1);
	//time(&end);
	//cost = difftime(end, start);
	//printf("%f/n", cost);
	arrive_time = 0;
	next = NULL;
}
string car::REchepaihao()
{
	return chepaihao;
}

void car::getchepai(string p)
{
	chepaihao = p;
}

int car::left_time()
{
	return 0;
}

void reading(car*&top)
{
	top = new car("YUILKVG78");
	string a[2] = { "YOVGYC98","UIRBP09" };
	for (int i = 0;i < 2;i++)
	{
		car* index = new car(a[i]);
		push(top, index);
	}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/384303.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号