#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;
}
没有与参数列表匹配的构造函数 "Student::Student" 实例 是什么意思
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- panfei625 2021-10-11 15:28关注
你的11-14行和44-47行的void student::show定义重复了。注释掉一个就可以了。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 请问有人会紧聚焦相关的matlab知识嘛?
- ¥15 网络通信安全解决方案
- ¥50 yalmip+Gurobi
- ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
- ¥15 itunes恢复数据最后一步发生错误
- ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
- ¥100 H5网页如何调用微信扫一扫功能?
- ¥15 讲解电路图,付费求解
- ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
- ¥15 three.js添加后处理以后模型锯齿化严重