Please take a look at the following code. When I do not put my pointers in an array the code works. See the commented out section. I thought it would be nice to do an array as I could then have more control over my output. I could also add additional items easier in the future.
The problem is when its in an array i never get prompted for input. Its like a big empty buffer.
#include <iostream>
#include "cdrom.h"
#include "cdromsupport.h"
using namespace std;
int main ()
{
// Declares 3 CDROM Pointers
CDROM *pCDROM1;
CDROM *pCDROM2;
CDROM *pCDROM3;
CDROM *pCDs[3];
//Check For Dynamic Memory Allocation
pCDROM1 = new CDROM;
if (pCDROM1 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
pCDROM2 = new CDROM;
if (pCDROM2 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
pCDROM3 = new CDROM;
if (pCDROM3 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
// Loads each CDROM with data
for (int i = 0; i < 3; i++)
{
pCDs[i]->loadInfo();
}
for (int i = 0; i < 3; i++)
{
pCDs[i]->displayInfo();
}
/*
pCDROM1->loadInfo();
pCDROM2->loadInfo();
pCDROM3->loadInfo();
pCDROM1->displayInfo();
pCDROM2->displayInfo();
pCDROM3->displayInfo();
// calls global function show cost
// showcost();
// Changes data on CDROM 1 and CDROM 2
pCDROM1->changeData();
pCDROM2->changeData();
pCDROM3->changeData();
// Redisplay CDROM with New Data
pCDROM1->displayInfo();
pCDROM2->displayInfo();
pCDROM3->displayInfo();
*/
// Call giveMemoryBack function
giveMemoryBack(pCDROM1, pCDROM2, pCDROM3);
return 0;
}