The error I'm getting when debugging (dynamic arrays): Unhandled exception at 0x5bfa782d in Ass4DynamicArrays.exe: 0xC0000005: Access violation writing location 0xabababab.

Can you wrap the whole thing in a try/catch block so you can see the message returned from the exception?

The error I'm getting when debugging (dynamic arrays): Unhandled exception at 0x5bfa782d in Ass4DynamicArrays.exe: 0xC0000005: Access violation writing location 0xabababab.

You'll have to post some code for anyone to know for sure what's going on, but you appear to be de-referencing an un-initialized pointer. Have you verified that you are allocating correctly before you attempt to access the information referenced by all of your pointers?

Another possibility (although unlikely given the wording of the error) is that you are attempting to de-reference a pointer that was previously valid, but its target has since been destroyed.

Edited 5 Years Ago by Fbody: n/a

Here is a code sample of where the possible cause of error could be:

void addRecord(vehicle *&p, int &size, string driverId, string regNum, string vehicleMake, string vehicleModel, string province)
{
	if(size == 0)
	{
		cout << "Enter Registration Detail: " << endl;
		cout << endl;
		cout << "Driver ID: ";
		getline(cin, p[size].driverId);
		cout << cout << "Registration Number: ";
		getline(cin, p[size].regNum);
		cout << "Vehicle Make: ";
		cin >> p[size].vehicleMake;
		cout << "Vehicle Model: ";
		cin >> p[size].vehicleModel;
		cout << "Province: ";
		cin >> p[size].province;
		cout << "Record successfully added" << endl;
	}
	else
	{
		vehicle *tmp = new vehicle[++size];

		for(int i = 0; i < (size - 1); i++)
			tmp[i] = p[i];
		
		cout << "Enter Registration Detail: " << endl;
		cout << endl;
		cout << "Driver ID: ";
		cin >> tmp[size - 1].driverId;
		cout << cout << "Registration Number: ";
		cin >> tmp[size - 1].regNum;
		cout << "Vehicle Make: ";
		cin >> tmp[size - 1].vehicleMake;
		cout << "Vehicle Model: ";
		cin >> tmp[size - 1].vehicleModel;
		cout << "Province: ";
		cin >> tmp[size - 1].province;
		cout << "Record successfully added" << endl;

		delete []p;
		p = tmp;
	}
}

Edited 5 Years Ago by Cross213: n/a

This article has been dead for over six months. Start a new discussion instead.