这是教授吹嘘的同学的正确代码,我不明白为什么它需要一个双重构造函数
class Studentrecords
{
private:
struct student
{
string name;
string address;
int ID;
double gpa;
};
student *stackArray;
int stackSize;
int top;
public:
Studentrecords();
Studentrecords(int size);
~Studentrecords();
void push(string name, string address, int id, double gpa);
void pop();
bool isFull() const;
bool isEmpty() const;
void display();
};
Studentrecords::Studentrecords(int size)
{
stackArray = new student[size];
top = 0;
}
Studentrecords::Studentrecords()
{
stackSize = 25;
stackArray = new student[stackSize];
top = 0;
}
Studentrecords::~Studentrecords()
{
delete [] stackArray;
}