【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;
}
相关推荐
夜晚中的人海2 分钟前
【C++】哈希表算法习题
c++·算法·散列表
水木姚姚7 分钟前
初识C++
开发语言·c++
权泽谦28 分钟前
新世代的 C++:当 ChatGPT 遇上模板元编程
开发语言·c++·chatgpt
MediaTea30 分钟前
Python 第三方库:Flask(轻量级 Web 框架)
开发语言·前端·后端·python·flask
2501_9411114034 分钟前
C++中的状态模式实战
开发语言·c++·算法
Dxxyyyy1 小时前
零基础学JAVA--Day34(Map接口+HashTable+HashMap+TreeSet+TreeMap+开发中如何选择集合实现类?(重要))
java·开发语言
rainFFrain2 小时前
qt显示类控件---QProgressBar
开发语言·qt
鑫—萍2 小时前
C/C++精品算法——双指针(1)
c语言·c++·算法
rainFFrain2 小时前
qt输入类控件---QComboBox/QSpinBox
开发语言·qt
2501_941111892 小时前
低延迟系统C++优化
开发语言·c++·算法