今天学习了C++的类,想请各位大佬看看有没有什么错!!
#include<iostream>
#include<cstring>
using namespace std;
int main(void) {
Student boy;
boy.agea(12);
boy.namea("lili");
int boyage = boy.getage();
string boyname = boy.getname();
cout << "姓名是" << boyname << "他的年龄是" << boyage << endl;
};
class Student {
public:
int agea(int age_a);
string namea(string name_q);
int getage(void);
string getname(void);
private:
int age;
string name;
};
int Student::agea(int age_a) {
age = age_a;
return age;
};
string Student::namea(string name_q) {
name = name_q;
return name;
};
int Student::getage(void) {
return age;
};
string Student::getname(void){
return name;
};
再次谢谢给位大佬!!!
全部评论
(2) 回帖