Comments & Documentation with Doxygen in C++
Good comments explain why, never what — the code already says what. File headers state purpose and ownership, tricky algorithms get rationale blocks, and public APIs get structured documentation that Doxygen turns into browsable HTML: /// brief lines, @param/@return tags, and @code examples.
Doxygen reads specially-marked comments (/// or /** */) straight from sources, so docs live beside the code they describe and rot slower than wikis. A documented header is a contract: purpose, parameters, return, preconditions, and thrown exceptions, all machine-extractable.
Why, not what
// skip weekends: payroll rule 4.2 justifies the odd branch; // increment i merely repeats the code.
Document the contract
Public functions get purpose, @param meanings and units, @return semantics, and @throw conditions — everything a caller must know.
Doxygen markup
/// Brief one-liner plus @param/@return blocks above each declaration; @code...@endcode for usage examples.
Generate and browse
doxygen Doxyfile renders HTML/LaTeX from the comments — API docs that rebuild with the code, every time.
/// Splits `line` on `delim`, dropping empty fields./// @param line the input text (unchanged)/// @param delim field separator character/// @return vector of non-empty fields#include <vector>#include <string>Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C++ yourself — building beats watching.