What C++ idioms should C++ programmers use?

Partial picture Partial · Nov 18, 2009 · Viewed 15.8k times · Source

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?

Answer

Jerry Coffin picture Jerry Coffin · Nov 18, 2009

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.