Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

examples of how to write beautiful c++ comments [closed]

Tags:

c++

comments

maybe is stupid question but is there any way to write good looking (short ) format to write comments for c++ function,headers,variable ? any visual examples?

like image 391
user63898 Avatar asked May 10 '11 05:05

user63898


People also ask

How do you write a good comment in C?

There are two ways to add comments in C: // - Single Line Comment. /*... */ - Multi-line Comment.

What is an example of comments in C?

Single-line comments start with two forward slashes ( // ). Any text between // and the end of the line is ignored by the compiler (will not be executed).

What is comment give an example?

1. A comment is text in a program's code, script, or another file that is not meant to be seen by the user running the program. However, is seen when viewing the source code. Comments help make code easier to understand by explaining what is happening and help prevent portions of a program from executing.


2 Answers

What do you mean by good looking here ? I do it like this ..

int c;//! loop Counter

/**
 * compares (XOR) two Types
 * return boolean result
 */
bool compare(Type l, Type r);

Its doxygen format. there are populer formats for documenting codes in Comment. Doxygen is one and another one is naturaldocs. there are even more. Its your flavour. You may even like the naturaldocs format.

/*
   Function: Compare
   Compares two Types
   Parameters:
      l - lhs
      r - rhs.
   Returns:
      boolean result

*/
bool compare(Type l, Type r);

The DOC++ format is also similer like.

/** Comparison
    Compare two Types

    @param l Type lhs
    @param r Type rhs
    @return boolean result
*/
bool compare(Type l, Type r);

Just use only one format and stick with it.

like image 116
Neel Basu Avatar answered Sep 20 '22 12:09

Neel Basu


I prefer using this style:

/**
 * Class name
 * Description
 */

class MyClass{

}
like image 27
Headshota Avatar answered Sep 21 '22 12:09

Headshota