【自用16.】C++类

类的构成

类的设计

代码demo

cpp 复制代码
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

// 定义一个"人类"
class Human {
public:  //公有的,对外的
	void eat(); //方法, "成员函数"
	void sleep();
	void play();
	void work();

	string getName();
	int getAge();
	int getSalary();

private:
	string name;
	int age;
	int salary;
};

void Human::eat() {
	cout << "吃炸鸡,喝啤酒!" << endl;
}

void Human::sleep() {
	cout << "我正在睡觉!" << endl; 
}

void Human::play() {
	cout << "我在唱歌! " << endl; 
}

void Human::work() {
	cout << "我在工作..." << endl;
}

string Human::getName() {
	return name;
}

int Human::getAge() {
	return age;
}

int Human::getSalary() {
	return salary;
}

int main(void) {
	Human  zhangshan;

	system("pause");
}
相关推荐
小镇敲码人3 分钟前
深入剖析华为CANN框架下的Ops-CV仓库:从入门到实战指南
c++·python·华为·cann
island131415 分钟前
CANN GE(图引擎)深度解析:计算图优化管线、内存静态规划与异构任务的 Stream 调度机制
开发语言·人工智能·深度学习·神经网络
坚持就完事了20 分钟前
Java中的集合
java·开发语言
魔芋红茶24 分钟前
Python 项目版本控制
开发语言·python
云小逸39 分钟前
【nmap源码解析】Nmap OS识别核心模块深度解析:osscan2.cc源码剖析(1)
开发语言·网络·学习·nmap
冰暮流星39 分钟前
javascript之二重循环练习
开发语言·javascript·数据库
风指引着方向40 分钟前
自定义算子开发入门:基于 CANN op-plugin 的扩展实践
开发语言
Fairy要carry1 小时前
面试-GRPO强化学习
开发语言·人工智能
Liekkas Kono1 小时前
RapidOCR Python 贡献指南
开发语言·python·rapidocr
张张努力变强1 小时前
C++ STL string 类:常用接口 + auto + 范围 for全攻略,字符串操作效率拉满
开发语言·数据结构·c++·算法·stl