【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;
}
相关推荐
W.A委员会1 天前
JS原型链详解
开发语言·javascript·原型模式
止语Lab1 天前
Go并发编程实战:Channel 还是 Mutex?一个场景驱动的选择框架
开发语言·后端·golang
她说彩礼65万1 天前
C# 实现简单的日志打印
开发语言·javascript·c#
绿浪19841 天前
c# 中结构体 的定义字符串字段(性能优化)
开发语言·c#
房开民1 天前
可变参数模板
java·开发语言·算法
t***5441 天前
如何在现代C++中更有效地应用这些模式
java·开发语言·c++
itman3011 天前
C语言、C++与C#深度研究:从底层到现代开发演进全解析
c语言·c++·c·内存管理·编译模型
Victoria.a1 天前
python基础语法
开发语言·python
xiaoyaohou111 天前
023、数据增强改进(二):自适应数据增强与AutoAugment策略
开发语言·python
鬼圣1 天前
Python 上下文管理器
开发语言·python