数组对象使用构造函数初始化的问题

图片说明图片说明图片说明

楼主你这样写不行的,只有定义的时候才能那么初始化
类里面加个成员函数用来设置变量的值SetValue

 class student
{
    string name;
    double score;
    static int num;
    static double sum;
public:
    student(string n = "no name", double s = 0):name(n),score(s)
    {
        num++;
        sum += score;
    }
    void SetValue(string n, double s)
    {
        name = n;
        score = s;
    }
    .........
};
....................
for(int i = 0; i < n; i++)
    {
        cin >> a>>b;
        p[i].SetValue(a, b);
    }

我觉得应该是p[i]=new student(a,b);