resize(cds) in createCDs function was not declared

//the error points to cds


/*

*/

#include "CDs.h"
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>

using namespace std;



//
CDs* createCDs(const char* filename,fstream &file)
{

const char* _file;
int max = 1;
int min = 0;
CD** cdPtrArray = new CD*[max];


file.open(filename);

while (!file.eof())
{
int year, rating, num_tracks;
string* title = new string[1];
string* artist = new string[1];
string* length = new string[1];


file >> artist[0];
file >> title[0];
file >> year;
file >> rating;
file >> num_tracks;

CD* c = createCD(artist, title, year, rating, num_tracks);
cdPtrArray[min] = c;



if (min == max)
{
resize(cds);
}
for (int i = 0; i < num_tracks; i++)
{
file >> length[0];
file >> title[0];
}
min++;
}
CDs* _cds = new CDs;
_cds -> num_cds = min;
_cds -> max_cds = min;
_cds -> cd_array = cdPtrArray;
return _cds;
}

//
void destroyCDs (CDs* cds)
{
int numCDs = cds -> num_cds;
CD** _cd = cds -> cd_array;

for ( int i = 0; i < numCDs; i++)
{
destroyCD (_cd[i]);
}
delete cds;
}

//
void displayCDs (CDs* cds)
{
int numAlbum = cds -> num_cds;

CD** _cd = cds -> cd_array;


for (int i = 0; i < numAlbum; i++)
{
cout << _cd[i] << endl;
}

}

//
void resize (CDs* cds)
{
int cd_nums = cds -> num_cds;
int cd_max = cds -> max_cds;
CD** cd = cds -> cd_array;
CD** cdPtr = new CD*[cd_max * 2];
for (int i = 0; i < cd_nums; i++)
{
cd[i] = cdPtr[i];
}
delete cd;

cd_max * 2;
}

//
CDs* findCDs (CDs* cds, string* artist)
{
CD* compact = NULL;

int numAlbum = cds -> num_cds;
CD** _cd = cds -> cd_array;

for (int i = 0; i < numAlbum; i++)
{

if(artist == compact )
{
_cd[i] = compact;
break;
}
}
return cds;
}

/////////////////////////////////////////////////////////////////////////////

/*

*/

#ifndef CDS_STRUCT
#define CDS_STRUCT

#include "CD.h"

using namespace std;

struct CDs
{
CD** cd_array;
int num_cds;
int max_cds;
};



//
CDs* createCDs(string filename, fstream &file );

//
void destroyCDs(CDs* cds);

//
void displayCDs(CDs* cds);

//
void resize(CDs* cds);

//
CDs* findCDs(CDs* cds, string* artist);


#endif
If you want to use the function resize(...) you need at least a prototype so that the compiler knows the signature:

1
2
3
4
5
6
void resize (CDs* cds); // The prototype

CDs* createCDs(const char* filename,fstream &file)
{
...
}


Really: Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/

It is more likely that you get help if you do.

[EDIT]
I see that you have already the prototypes in a header (CDS_STRUCT?). You need to include that header.
Last edited on
Topic archived. No new replies allowed.