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

Recommended Answers

All 7 Replies

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

0xabababab looks like debugger fluff for an uninitialized pointer.

How do you mean? I dont understand try/catch block

Whats debugger fluff?

It's a bogus address designed to stand out and be obviously wrong.

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.

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;
	}
}
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.