I need to write a function that will use the delete command on a pointer. I'm in left field. See what I have so far any suggestions. I don't think I'm quite getting what I need to pass to the function and pass back.
#include <iostream>
#include "cdrom.h"
using namespace std;
int main ()
{
// Declares 3 CDROM Pointers
CDROM *pCDROM1;
CDROM *pCDROM2;
CDROM *pCDROM3;
pCDROM1 = new CDROM;
pCDROM2 = new CDROM;
pCDROM3 = new CDROM;
//Check For Dynamic Memory Allocation
if (pCDROM1 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
if (pCDROM2 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
if (pCDROM3 == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
}
// Loads each CDROM with data
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();
// Redisplay CDROM with New Data
pCDROM1->displayInfo();
pCDROM2->displayInfo();
pCDROM3->displayInfo();
// Call giveMemoryBack function
int giveMemoryBack(int *pCDROM1, int *pCDROM2, int *pCDROM3);
return 0;
}
int giveMemoryBack (int *pCDROM, int *pCDROM2, int *pCDROM3)
{
delete *pCDROM1
delete *pCDROM2
delete *pCDROM3
return 0;
}