没有带U盘 暂且把问题记在这里吧
1.对于内含类变量的函数 当存在Student(const Student &s)时候,怎样让其中类变量获取数值?
2.Student(int n=10,char *m="aaa",Date d);时,出现 了missing default parameter for parameter 3 如何解释?
class Date
{
private:
int day;
int month;
int year;
public:
Date();
Date(Date &b);
void show();
void setDate(int a,int b,int c);
};
class Student
{
private:
int number;
char *name;
Date birth;
public:
Student();
Student(int n,char *m,Date d);
Student(const Student &s);
~Student();
void setnumber(int n);
void setname(char *s);
void setbirth(Date d);
void printstudent();
};
//两个类的代码
#include "iostream.h"
#include "string.h"
class Date
{
private:
int day;
int month;
int year;
public:
Date();
Date(Date &b);
void show();
void setDate(int a,int b,int c);
};
Date::Date()
{
day=0;
month=0;
year=0;
}
Date::Date(Date &b)
{
day=b.day;
month=b.month;
year=b.year;
}
void Date::show()
{
cout<<day<<endl;
cout<<month<<endl;
cout<<year<<endl;
}
void Date::setDate(int a,int b,int c)
{
day=a;
month=b;
year=c;
}
class Student
{
private:
int number;
char *name;
Date birth;
public:
Student();
Student(int n,char *m,Date d);
Student(const Student &s);
~Student();
void setnumber(int n);
void setname(char *s);
void setbirth(Date d);
void printstudent();
};
Student::Student()
{
number=0;
strcpy(name,"aaa");
}
Student::Student(int n,char *m,Date d):birth(d)
{
number=n;
strcpy(name,m);
}
Student::Student(const Student &s)
{
number=s.number;
strcpy(name,s.name);
}
Student::~Student()
{
cout<<"析构执行!"<<endl;
}
void Student::setnumber(int n)
{
number=n;
}
void Student::setname(char *s)
{
strcpy(name,s);
}
void Student::printstudent()
{
cout<<number<<endl;
cout<<name<<endl;
}