【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;
}
相关推荐
t***5446 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
oy_mail7 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1207 小时前
PHP操作redis
开发语言·redis·php
nashane7 小时前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
yolo_guo7 小时前
redis++使用: hmset 与 hmget
c++·redis
凌波粒8 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
handler018 小时前
拒绝权限报错!三分钟掌握 Linux 权限管理
linux·c语言·c++·笔记·学习
拾贰_C8 小时前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
t***5449 小时前
如何在Dev-C++中选择Clang编译器
开发语言·c++