Hello guys i keep getting a

Unhandled exception at 0x7c177ac0 (mfc71d.dll) in LSMUtility.exe: 0xC0000005: Access violation reading location 0xcdcdcdbd.

However according to MSDN the code is right:

void CTemp::OnDelete()
{
	// TODO: Add your control notification handler code here
	CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
	
	if(pos != main_dlg->BTList.GetTailPosition())
	{
		main_dlg->BTList.RemoveAt(pos);
		MessageBox("deleted");
	}
}

the above code works and the error only occurs if itterate through the list by using Next and Back buttons and functions:

void  CTemp::OnNext()
{
	// TODO: Add your control notification handler code here
		CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
		if(pos != main_dlg->BTList.GetTailPosition())
	{
		 main_dlg->BTList.GetNext(pos);
		Display();
	}
	else
		MessageBox("end");
}

//and Pervious

void CTemp::OnPervious()
{
	// TODO: Add your control notification handler code here
	CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
	if(pos != main_dlg->BTList.GetHeadPosition())
	{
		 main_dlg->BTList.GetPrev(pos);
		Display();
	}
	else

		MessageBox("At beginning");
}

Can anyone suggest where i've gone wrong please?

Thanks

Access violation reading location 0xcdcdcdbd.

Isn't that how uninitialized memory is filled in debug mode?

Access violation reading location 0xcdcdcdbd.

Isn't that how uninitialized memory is filled in debug mode?

I think so, but I'm not sure how to fix it, it would appear that when i delete an object from the list, it gets deleted, but if i click pervious that works but then if i delete that and click 'next' i get that error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.