C++笔记之enum class和emun的区别

news/2025/2/15 12:01:16/

C++笔记之enum class和emun的区别

code review!
在这里插入图片描述

代码,使用 enum class 的示例:

#include <iostream>enum class Month { January, February, March, April, May, June, July, August, September, October, November, December };int main() {Month currentMonth = Month::August;if (currentMonth == Month::August) {std::cout << "It's August!" << std::endl;}// Uncommenting the following line will result in a compilation error// if (currentMonth == December) {//     std::cout << "It's December!" << std::endl;// }return 0;
}

代码,使用普通的 enum 的示例:

#include <iostream>enum Month { January, February, March, April, May, June, July, August, September, October, November, December };int main() {Month currentMonth = August;if (currentMonth == August) {std::cout << "It's August!" << std::endl;}// The following line compiles successfully, but it's not type-safeif (currentMonth == December) {std::cout << "It's December!" << std::endl;}return 0;
}

http://www.ppmy.cn/news/1013415.html

相关文章

04-4_Qt 5.9 C++开发指南_时间日期与定时器

文章目录 1. 时间日期相关的类2. 源码2.1 可视化UI设计2.2 dialog.h2.3 dialog.cpp 1. 时间日期相关的类 时间日期是经常遇到的数据类型&#xff0c;Qt 中时间日期类型的类如下。 QTime:时间数据类型&#xff0c;仅表示时间&#xff0c;如 15:23:13。 QDate:日期数据类型&…

yolo txt 转 labelme json 格式

talk is cheap show me the code! def convert_txt_to_labelme_json(txt_path, image_path, output_dir, image_fmt.jpg):# txt 转labelme json# 将yolo的txt转labelme jsontxts glob.glob(os.path.join(txt_path, "*.txt"))for txt in txts:labelme_json {versio…

java文件

一.File类 二.扫描指定目录&#xff0c;并找到名称中包含指定字符的所有普通文件&#xff08;不包含目录&#xff09;&#xff0c;并且后续询问用户是否要删除该文件 我的代码: import java.io.File; import java.io.IOException; import java.util.Scanner;public class Tes…

SQLAlchemy与标准SQL相比有哪些优点?

让我来给你讲讲SQLAlchemy和标准SQL相比有哪些优点吧&#xff01; 首先&#xff0c;我们要知道&#xff0c;SQLAlchemy是一个Python的SQL工具包和对象关系映射&#xff08;ORM&#xff09;系统&#xff0c;它把Python的面向对象编程&#xff08;OOP&#xff09;的理念带入了数…

机器学习笔记之优化算法(十一)凸函数铺垫:梯度与方向导数

机器学习笔记之优化算法——凸函数铺垫&#xff1a;梯度与方向导数 引言回顾&#xff1a;偏导数方向余弦方向导数方向导数的几何意义方向导数的定义 方向导数与偏导数之间的关联关系证明过程 梯度 ( Gradient ) (\text{Gradient}) (Gradient) 引言 本节作为介绍凸函数的铺垫&a…

FastAPI 构建 API 高性能的 web 框架(一)

如果要部署一些大模型一般langchainfastapi&#xff0c;或者fastchat&#xff0c; 先大概了解一下fastapi,本篇主要就是贴几个实际例子。 官方文档地址&#xff1a; https://fastapi.tiangolo.com/zh/ 1 案例1:复旦MOSS大模型fastapi接口服务 来源&#xff1a;大语言模型工程…

封装上传文件组件(axios,onUploadProgress,取消请求)

目录 定时模拟进度条 方法 A.axios B.xhr 取消请求​​​​​​​ 完整代码 A.自定义上传组件 B.二次封装组件 情况 增加cancelToken不生效&#xff0c;刷新页面 进度条太快->设置浏览器网速 定时模拟进度条 startUpload() {if (!this.file) return;const totalS…

0基础学习VR全景平台篇 第79篇:全景相机-泰科易如何直播推流

泰科易科技是中国的一家研发全景相机的高科技公司&#xff0c;前不久&#xff0c;在2020世界VR产业大会上发布了新一代5G VR直播影像采集终端--360starlight。以其出色的夜景成像效果和一“部”到位的直播方案重新定义了VR慢直播相机&#xff0c;对行业具有高度借鉴意义。 本文…