花火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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵