c++ - 没有重载函数的实例与指定的类型匹配 (C++)
问题描述
#include <iostream>
#include <string>
using namespace std;
class student {
private:
string sname;
float gpa;
public:
student(string name, float g = 0.0);
~student();
};
struct student {
string name;
int gpa;
void display();
};
student::student(string name, float g) { // **this is where I get the error**
cout << "student constructor is running..." << endl;
student stu;
stu.name += name;
stu.gpa = g;
}
student::~student() {
// cout << "Student No." << endl;
cout << "student destructor is running..." << endl;
}
void student::display() {
cout << "Student Name: " << name << endl;
cout << "Student GPA: " << gpa << endl;
}
这是一个学生头文件。错误出现了:没有构造函数“student::student”的实例与参数列表匹配。我不明白为什么以及如何解决这个问题。
解决方案
编译器将学生视为结构,更改学生结构名称
推荐阅读
- apache-kafka - 手动分配到特定分区的 Kafka 消费者在轮询时不返回任何内容
- python - 如何将 JSON 树结构转换/转换为 merkle 树
- javascript - 使用 android 意图在亚马逊应用程序中打开链接
- excel - 如何根据该表中的单元格值动态保护excel表
- html - react-native-webview中的视口比例保持标题的字体大小
- php - 用户是否可以通过 Livewire 中的 ajax 请求更改模型实例?
- integration-testing - EFCore 5 与 SQL-SERVER localdb 的集成测试:迁移问题
- javascript - CSS伪元素不显示svg背景图片
- javascript - Onmousedown 不允许我点击链接
- spring-boot - 通过 Docker 运行 bootRun 时无法获取 gradle.properties