【C++】结构体、重载

cpp 复制代码
#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;
}
相关推荐
感哥5 小时前
C++ lambda 匿名函数
c++
沐怡旸11 小时前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥12 小时前
C++ 内存管理
c++
博笙困了18 小时前
AcWing学习——双指针算法
c++·算法
感哥18 小时前
C++ 指针和引用
c++
感哥1 天前
C++ 多态
c++
沐怡旸1 天前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River4162 天前
Javer 学 c++(十三):引用篇
c++·后端
感哥2 天前
C++ std::set
c++
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法