-
testing constructors..
I have been given the following class structure:
class UnsortedType
{
public:
UnsortedType(); // default constructor
UnsortedType(int); // regular constructor
void MakeEmpty(); // set list to empty
bool IsEmpty(); // test for an empty list (true if empty)
bool IsFull(); // test for a full list (true if full)
bool InsertItem(student); // add item to list
void ResetList(); // set next pointer to beginning of list
bool GetNextItem(student&); // get next sequential item
private:
int length; // number of items in list plus subscript of next add
int currentPos; // item to retrieve on Get Next Item function
int maxItems; // from user constructor for size of array
student* info; // pointer to the student array
};
Part of my assignment is to test all the function listed including the constructors. There is a default and a regular one:
UnsortedType::UnsortedType() // default constructor
{
length = 0;
currentPos = -1;
maxItems = 1;
info = new student[1];
}
UnsortedType::UnsortedType(int n) // regular constructor
{
length = 0;
currentPos = -1;
maxItems = n;
info = new student[maxItems];
}
My program has in it the following class declaration:
UnsortedType myType; // Declaration of myType class
I have a function called InitializeArray where I'm attempting to test the regular constructor to see if it will work:
void InitializeArray() // Function heading
// This function initializes student class to a certain number of items determined by the user.
{
int num = 1;
myType.UnsortedType(num);
cin.ignore(10, '\n');
system("cls");
cout << " Default constructor is initialized. maxItems is set to 1." << endl
<< " Press enter to continue...";
cin.get();
return;
}
What is wrong with this code and how do I test for both constructors? :confused:
Thanks!