【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;
}
相关推荐
csdn_aspnet4 小时前
C++ 使总距离最短的最佳点位置(Optimum location of point to minimize total distance)
c++·算法
代码民工正电荷5 小时前
JAVA重要知识点和集合
java·开发语言
星恒随风5 小时前
C++11 加餐(4)并发支持库——condition_variable 条件变量与生产者消费者模型
开发语言·c++
利威尔xu5 小时前
Go map 并发十连问:多 goroutine 同时读写触发 fatal error,进程直接崩溃
开发语言·golang
你不知道我是谁?6 小时前
GESP C++ 补充知识:浮点数格式化输出(%f/%e/%g)与 fmod 浮点余数实战
开发语言·c++
九蝶科技6 小时前
运费分摊的二开实现:BigDecimal 精确分摊 + 尾差补齐 + 暂估调整
开发语言·python
Ryan-Zhong7 小时前
一次接入 16 个平台:视频链接元数据解析 API 的 Python 实战与踩坑记录
开发语言·python·dreamweaver
Rabitebla7 小时前
【Linux】 文件系统(五):挂载与软硬链接,多个文件系统怎样组成统一目录树
linux·运维·服务器·c++·笔记·学习·算法
无限聚核8 小时前
PHP 对接美团、抖音团购核销接口:预核销、核销、重试和撤销一份代码跑通,无限聚核
开发语言·php·美团·团购核销接口
WL学习笔记9 小时前
继承(C++)
c++·继承