The following function must allocate memory for a database of objects, assigning a pointer to the array of objects.
A pointer will then loop down the array using pointer arithmetic and initialize each object to the correct values, following user input.
Here is the code that doesn't work:
//**********************************************************************
//* Get Database Records *
//**********************************************************************
record* get_records_database(int quantity)
{
record *p_database; // Pointer to the records database
record *p_record; // Pointer to each object in the database
int index = 1; // Number of objects in the database
// Allocate a database of object records
try
{
p_database = new record[quantity];
}
catch (bad_alloc xa)
{
fatal_error(ALLOC_ERR, "get_records_database",
"object records database");
}
// Loop processing object records until the database is filled
// --- //
// Test:
p_database->set_amount(400);
p_database->get_amount();
return p_database;
}
The problem I face is fixing the following compiler error in VisualStudio: error C4703: potentially uninitialized local pointer variable 'p_employee_database' used.
This is a project; using new, try, catch, and pointers, is required; the structure of the function is required (not all written at this point); the return value of a pointer to a class is required. My teacher is extremely strict in following his requirements precisely.
Any help to the resolution of this error is greatly appreciated. Thank you ;)