返回课程
AI013 专业级

现代 C++ 教程

本教程旨在为有经验的开发者提供 C++11/14/17/20 新特性的快速参考。内容涵盖语言易用性改进、运行时性能提升、新容器、智能指针与内存管理、正则表达式、并发编程,以及对 C++20 的前瞻介绍。

4.8
30.0h
318 名学生
10 lessons
2 点赞
人工智能
开始学习

课程概述

📚 内容概要

本教程旨在为有经验的开发者提供 C++11/14/17/20 新特性的快速参考。内容涵盖语言可用性提升、运行时性能改进、新容器的使用、智能指针与内存管理、正则表达式、并发编程,以及对 C++20 的前瞻介绍。

快速掌握 C++11/14/17/20,迈入现代 C++ 编程的大门。

作者: 欧长坤 (Ou Changkun)

致谢: 采用 CC BY-NC-ND 4.0 协议授权,感谢所有 GitHub 贡献者及相关社区支持。

🎯 学习目标

  1. 使用命令行工具识别并验证 C++ 编译环境和目标架构。
  2. 解释 C(C89、C99、C11)与 C++(C++98、C++1x)之间的标准兼容性和重叠历史。
  3. 通过 extern "C" 头文件和多阶段编译工作流实现跨语言功能链接。
  4. 使用 nullptr 解决指针歧义,并利用 constexprif constexpr 实现编译期逻辑。
  5. 使用 autodecltype 和类型别名(using)简化复杂声明,同时通过 overridefinal 确保稳健的面向对象设计。
  6. 利用可变模板、折叠表达式和非类型模板参数推导设计高度泛化的代码。
  7. 使用多种捕获模式(值捕获、引用捕获、表达式捕获和通用捕获)定义和实现 Lambda 表达式。
  8. 使用 std::functionstd::bind 创建灵活的函数包装器和部分函数应用。
  9. 将表达式分类为左值(Lvalues)、纯右值(Prvalues)和将亡值(Xvalues),并应用移动语义优化类资源管理。
  10. 区分 std::array(固定大小、栈分配)和 std::vector(动态大小、堆分配)的内存模型及其适用场景。

课程

Lesson

This lesson explores the evolution of C++ and the importance of adopting modern, type-safe coding practices over legacy C-style habits. Students will learn to utilize explicit casting operators and compiler diagnostics to improve code stability, security, and performance.

This lesson explores modern C++ language usability by addressing the "NULL Trap" through the introduction of `nullptr` and examining how `constexpr` and `noexcept` shift computation and error handling to compile-time. Students will learn to improve code safety and performance by replacing legacy C-style macros and casts with modern, type-safe alternatives.

This lesson explores performance optimization in modern C++ through move semantics, lambda expressions, and efficient memory management. Students will learn to leverage zero-cost abstractions like std::array and SFINAE to improve code performance and type safety in resource-constrained environments.

This lesson explores the transition from legacy C-style arrays to the modern std::array, highlighting how the latter provides type safety and STL integration without sacrificing performance. Students will learn to leverage stack-based memory allocation, bounds-checking, and perfect forwarding to write more efficient and robust C++ code.

This lesson explores the pitfalls of manual memory management, such as memory leaks and dangling pointers, and introduces RAII (Resource Acquisition Is Initialization) as a safer, automated alternative. Students will learn how to utilize smart pointers like std::unique_ptr, std::shared_ptr, and std::weak_ptr to ensure deterministic resource cleanup and exception safety in modern C++.

This lesson explores the transition from imperative, manual string searching to declarative pattern matching using regular expressions and formal grammars. Students will learn to apply regex metacharacters and anchors to efficiently parse unstructured data while understanding the performance benefits of using Deterministic Finite Automata.

This lesson explores the transition to standardized concurrency in C++11, which introduced a formal memory model and native thread support to replace platform-specific APIs. Students will learn to manage thread lifecycles, ensure cross-platform data consistency with standardized types, and use the noexcept specifier to maintain program stability in multi-threaded environments.

This lesson explores the evolution of C++ from platform-specific coding to a unified, high-level abstraction layer, focusing on the transition from legacy macros to modern standards. Students will learn to leverage C++11 concurrency features and C++23 filesystem utilities to write portable, maintainable code that avoids OS-specific dependencies.

This lesson explores modernizing C++ development by transitioning from platform-specific APIs to standardized, high-level abstractions like task-based parallelism and the C++11 memory model. Students will learn to improve code maintainability and safety by utilizing features such as std::future, std::atomic, and extended integer types like long long int.

This lesson explores the evolution of C++20, focusing on the "Big Four" features—Concepts, Modules, Coroutines, and Ranges—that shift the language toward a more declarative and efficient programming model. Students will learn how these tools improve code safety, reduce build times, and replace complex template metaprogramming with clearer, constrained syntax.