花火ios 2021-10-10 13:35 采纳率: 100%
浏览 165
已结题

没有与参数列表匹配的构造函数 "Student::Student" 实例 是什么意思


#include<iostream>
#include <string>
using namespace std;
class Student
{
public:
    Student(char* name, int age, float score);
    Student();
    ~Student();
    void show()
    {
    cout << m_name << "的年龄是" << m_age << ",成绩是" << m_score << endl;
    }
public:   //声明静态成员函数
    static int getTotal();
    static float getPoints();
private:  //声明静态成员变量
    static int m_total;//总人数
    static float m_points;//总成绩
private:
    char* m_name;
    int m_age;
    float m_score;

};

int Student::m_total = 0; 
float Student::m_points = 0.0;

Student::Student() {
    cout << "这是构造函数" << endl;
}
Student::Student(char* name, int age, float score) :
    m_name(name),m_age(age),m_score(score)
{
    m_total++;
    m_points += score;

}
Student::~Student() {
    cout << "这是析构函数" << endl;
}
void Student::show()
{
    cout << m_name << "的年龄是" << m_age << ",成绩是" << m_score << endl;
}
//定义静态成员函数
int Student::getTotal()
{
    return m_total;
}
float Student::getPoints()
{
    return m_points;
}
int main()
{
    Student stu1("小明", 15, 90.6);
    Student stu2("李磊", 16, 80.5);
    Student stu3("张华", 16, 99.0);
    Student stu4("王康", 14, 60.8);
      stu1.show();
    stu2.show();
    stu3.show();
    stu4.show();
    int total = Student::getTotal();
    float points = Student::getPoints();
    cout << "当前共有" << total << "名学生,总成绩是" << points << ",平均分是" << points / total << endl;
    return 0;
}
  • 写回答

2条回答 默认 最新

  • panfei625 2021-10-11 15:28
    关注

    你的11-14行和44-47行的void student::show定义重复了。注释掉一个就可以了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月30日
  • 已采纳回答 10月22日
  • 创建了问题 10月10日

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法