c++之 构造重载函数调用不明确
#include<iostream>#include<cstring>
using namespace std;
class Student
{
public:
int id;
char name[50]; // Data field
int age; // Data field
Student();
Student(int fid, char* fname, int fage);
//void set(int, char*, int);
//void print();
};
Student::Student(int fid = 0, char* fname = "No Name", int fage = 0)
{
id = fid;
strcpy(name,fname);
age = fage;
}
Student::Student()
{
id = 0;
strcpy(name,"No Name");
age = 0;
}
void set(Student &student, int pid = 0, char* pname = "No Name", int page = 0)
{
student.id = pid;
strcpy(student.name,pname);
student.age = page;
}
void print(Student student)
{
cout << student.name << " (" << student.id << ") " << "is " << student.age << " years old." << endl;
}
int main()
{
Student std1, std2(123, "Larry Jordan", 18), std3(124);//对重载函数的调用不明确
set(std1, 100, "Steven Gates", 61);
print(std1);
print(std2);
print(std3);
return 0;
}
请问这到底是为什么啊?谢谢各位!