没有与参数列表匹配的构造函数 "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;
}

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


 
#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;
}