我使用的IDE是visual studio2019.
现我定义了一个学生类student。并且完成了构造函数与析构函数的声明和定义。但我在主函数调用构造函数时,编译器报错:“没有与参数列表相匹配的构造函数实例”。
编译器报错显示:主函数中的student stu(1,"wang",18,86)中的“1”没有与参数列表相匹配的构造函数实例
以下是我的代码
#include<iostream>
using namespace std;
class student
{
private:
int id;
char* name;
int age;
float score;
public:
student(int i, char* n, int a, float s);
student(student&);
~student();
void printstu();
};
student::student(int i, char* n, int a, float s)
{
cout << "constructing..." << endl;
id = i;
name = new char[strlen(n) + 1];
age = a;
score = s;
if (name != 0)
{
strcpy(name, n);
}
}
student::student(student&s)
{
cout << "copy constructing..." << endl;
id = s.id;
age = s.age;
score = s.score;
name = new char[strlen(s.name) + 1];
if (name != 0)
{
strcpy(name, s.name);
}
}
student::~student()
{
cout << "destructing..." << endl;
delete[]name;
name = 0;
}
void student::printstu()
{
cout << "学号:" << id << "姓名:" << name;
cout << "年龄:" << age << "成绩:" << score << endl;
}
void main()
{
student stu(1, "wang", 18, 86);
stu.printstu();
}
请教解答,orz