C++程序员应该使用哪些C++习语?[英] What C++ idioms should C++ programmers use?

本文是小编为大家收集整理的关于C++程序员应该使用哪些C++习语?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

C ++成语C ++程序员应该知道什么?

由C ++成语,我的意思是设计模式或仅适用于C ++或更适用于C ++的某些事情的方式.

为什么应该使用这些成语,而这些成语是什么?

推荐答案

这是一个 list .如果我不得不选择一对夫妇,我可能会选择奇怪的重复模板模式或虚拟续线结构.

其他推荐答案

到目前为止,C ++所独有的最重要的"模式"是 raii (资源获取是初始化).

编辑:(回答已编辑为问题的额外问题).您主要使用RAII来(半)自动化资源管理.最明显的用途是在拥有对象脱离范围时,释放对象拥有的资源,例如释放内存或关闭文件.

其他推荐答案

pimpl,aka p ointer inpland> intheration?

本文地址:https://www.itbaoku.cn/post/627718.html

问题描述

What C++ idioms should C++ programmers know?

By C++ idioms, I mean design patterns or way of doing certain things that are only applicable for C++ or more applicable for C++ than most other languages.

Why one should use the idioms, and what do the idioms accomplish?

推荐答案

Here is one list. If I had to pick a couple I might go with the Curiously Recurring Template Pattern or Virtual Contstructors.

其他推荐答案

By far the single most important "pattern" to learn and know that's (nearly) unique to C++ is RAII (Resource Acquisition Is Initialization).

Edit: (To answer extra question edited into the question). You use RAII primarily to (semi-)automate resource management. The most obvious use is freeing resources owned by objects when the owning objects go out of scope, such as freeing memory or closing files.

其他推荐答案

PIMPL, aka P ointer to IMPL ementation ?