C2100非法的间接寻址问题


#include <iostream>
using namespace std;
#define MAXSIZE 100
typedef int Status;
typedef struct
{
    int id;
    string name;
    int age;
    int gender;
}student;
typedef struct
{
    student* base;//栈底指针
    student* top;//栈顶指针
    int stacksize;//栈可用的最大容量
}SqStack;
Status InitStack(SqStack& S)
{
    S.top = new student[MAXSIZE];//分配最大容量
    if (!S.base) 
    {
        cout << "分配失败" << endl;
        return 0;
    }//分配错误
    S.top = S.base;//top初始威base空栈
    S.stacksize = MAXSIZE;//stacksize设为MAXSIZE
    return 1;
}
void menu()
{
    cout << "--------------------1.入栈          2.出栈--------------------" << endl;
    cout << "--------------------3.删除栈顶      4.遍历栈--------------------" << endl;
    cout << "--------------------5.求栈长度      6.清空栈--------------------" << endl;
    cout << "--------------------7.销毁栈        8.退出--------------------" << endl;
}
//入栈功能
void PushToStack(SqStack& s)
{
    int n, flag;
    student *e;
    cout << "请输入需要入栈的元素个数:" << endl;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cout << "请输入各元素的值的id、name、age、gender:" << endl;
        cin >> e->id>>e->name>>e->age>>e->gender;
        if (s.top - s.base == MAXSIZE)
        {
            cout << "栈满,出栈" << endl;
            return;
        }
        *(s.top)->id = e->id;//错误位置
        *(s.top)->gender = e->gender;//错误位置
        *(s.top)->id = e->id;//错误位置
        *(s.top)->name = e->id;//错误位置
        s.top++;
        //这里如果是*(++s.top)则*(s.base)是未知数字;
    }
}



怎么改

程序有四个问题:
1、21行应该是

S.base = new student[MAXSIZE]; 

2、42行e需要初始化一个对象

student *e = new student;

3、54行应该是

(s.top)->id = e->id; // s.top是student*, 用->访问成员变量

或者是

(*(s.top)).id = e->id; // *(s.top)是student对象,用.访问成员变量,同时.的优先级高于*,需要加括号

4、54到57行左右变量名不一致