#include <iostream>
#include <cstring> //<==><string.h>
#include <cstdio>
#include <string>
using namespace std;
class stu
{
private:
int age;
string sex;
string name;
public:
double grade;
void set(int a,string s,string n);
int getAge();
string getSex();
string getName();
};
int stu::getAge()
{
return age;
}
string stu::getName()
{
return name;
}
string stu::getSex()
{
return sex;
}
void stu::set(int a,string s,string n)
{
age = a;
sex = s;
name = n;
}
int main()
{
stu jack;
jack.set(22,"na","jack");
cout << jack.getAge() << endl;
cout << jack.getName() << endl;
return 0;
}
【C++】结构体、重载
最新推荐文章于 2024-01-17 11:02:47 发布