2025年5月22日

C++ auto与decltype关键字详解

摘要: 一、auto关键字核心特性 1.1 基本功能 自动类型推导:编译器根据初始化表达式推断变量类型 简化代码:替代复杂类型声明(如迭代器、模板类型) std::vector<std::map<int, std::string>> data; auto iter = data.begin(); // 推导 阅读全文

posted @ 2025-05-22 01:12 无穷小学弟 阅读(38) 评论(0) 推荐(0)

深入理解C++左值、右值与完美转发

摘要: 一、左值与右值的本质区别 1.1 基本定义 左值(Lvalue):具有持久状态的对象 特点:有明确的内存地址 示例:变量、解引用指针 int x = 10; // x是左值 int* p = &x; // 可以取地址 右值(Rvalue):临时存在的对象 特点:即将销毁的临时值 示例:字面量、函数返 阅读全文

posted @ 2025-05-22 01:07 无穷小学弟 阅读(10) 评论(0) 推荐(0)

深入理解C++移动语义与资源管理

摘要: 一、移动语义:从拷贝到资源转移 1.1 拷贝构造 vs 移动构造 拷贝构造:创建独立副本,源对象保持不变// 传统拷贝构造函数 MyClass(const MyClass& other) { arr = new int[size]; // 深拷贝 memcpy(arr, other.arr, siz 阅读全文

posted @ 2025-05-22 01:02 无穷小学弟 阅读(30) 评论(0) 推荐(0)

导航