Nevermind, I see what you did. Change to this:
Code:
typedef struct DataRec
{
char DataType;
string DataName;
string DataAddress;
int DataClass;
string DataSSN;
float DataPUB_GPA;
string DataRank;
};
const int MAX_ITEMS = 6;
class PersonData
{
public:
void ReadInfo( DataRec data[], int& count );
//some functions
//
private:
DataRec data[MAX_ITEMS];
int count;
};
Further, you might add this:
Code:
class DataRec
/*...much easier, right? Remember, a class and struct are equivalent, except that structs default to public, classes to private...*/
{
char DataType;
string DataName;
string DataAddress;
int DataClass;
string DataSSN;
float DataPUB_GPA;
string DataRank;
};
class PersonData
{
public:
PersonData(int max = 6) :max_items(max)
{
data = new DataRec[max_items];
}
~PersonData()
{
if(data)
delete[] data;
}
void ReadInfo( DataRec data[], int& count );
//...
private:
DataRec *data;
int count;
int max_items;
};
This gives you more control over the size of the array, in a sense and also preserves encapsulation better...
[edit]
One more thing, you have a prototype argument that is identical to one of your classes internal variables:
Code:
void ReadInfo( DataRec data[], int& count );
Change to something like:
Code:
void ReadInfo( DataRec _data[], int& count );
Finally, you might consider simply storing a pointer to that parameter instead of having an entire copy within the object, thus saving yourself hundreds or thousands of bytes and also time spent copying.... If that suits you better then try:
Code:
class DataRec
{
char DataType;
string DataName;
string DataAddress;
int DataClass;
string DataSSN;
float DataPUB_GPA;
string DataRank;
};
class PersonData
{
public:
PersonData()
{
/*empty*/
}
PersonData(DataRec * pData, int& pCount)
{
ReadInfo(pData, &pCount);
}
~PersonData()
{
/*empty*/
}
void ReadInfo( DataRec *pData, int& pCount ){
data = pData;
count = &pCount;
}
//...
private:
DataRec *data;
int * count; //..in case the count changes...
};