为什么无法给指针赋值?

DeH40 2016-12-25 11:11:37
参照数据结构课本中的尾插法建表(其中temp是在另一个cpp文件中声明的全局变量)
void theList::CreateList(CarData a[],int n){
CarList * s,*r;
extern CarList * temp;
r=temp;
for(int i=0;i<n;i++)
{
s=(CarList *)malloc(sizeof(CarList));
s->data=a[i];
temp->next=s;
temp=s;
}

temp->next=NULL;
return ;
}

在执行到
s->data=a[i];
时报错:
DepotManage.exe 中的 0x0f57ca08 (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 写入位置 0xcdcdcdcd 时发生访问冲突
s->data=a[i];
前加上一句
cout<<a[i].id<<endl;
可以显示其中内容。
请问如何解决,十分感谢!
...全文
395 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
www_adintr_com 2016-12-26
  • 打赏
  • 举报
回复
0xcdcdcdcd 明显就是未初始化的数据
ri_aje 2016-12-26
  • 打赏
  • 举报
回复
CarList 怎么定义的?
小灸舞 2016-12-26
  • 打赏
  • 举报
回复
你使用了未初始化的堆空间 windows里常见的内存填充数据含义 * 0xABABABAB : Used by Microsoft's HeapAlloc() to mark "no man's land" guard bytes after allocated heap memory * 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers * 0xBAADF00D : Used by Microsoft's LocalAlloc(LMEM_FIXED) to mark uninitialised allocated heap memory * 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed to the debugger * 0xBEEFCACE : Used by Microsoft .NET as a magic number in resource files * 0xCCCCCCCC : Used by Microsoft's C++ debugging runtime library to mark uninitialised stack memory * 0xCDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory * 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates the crash * 0xFDFDFDFD : Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory * 0xFEEEFEEE : Used by Microsoft's HeapFree() to mark freed heap memory
  • 打赏
  • 举报
回复
为什么第一个参数要传指针呢?
lsfv001 2016-12-26
  • 打赏
  • 举报
回复
a[i],是一个类对象。&a[i]看看。

64,654

社区成员

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

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