DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
| Code Block |
|---|
#include <iostream>
using namespace std;
namespace ts
{
/**
* @brief Demonstrates how to format code
* This class demonstrates to developers how we should structure code
*/
class Counter
{
public:
Counter():_count(0), _totalCount(0) { }
/**
* @brief Increments the count by one or an optional value
* @param delta The amount to increment the count, default is 1
*/
void increment(int delta = 1) {
_count += delta;
}
/**
* @brief Returns the count value
* @return Count value
*/
int getCount() const { // try to use const as much as possible
return _count;
}
private: // try to hide data
void _helpers() { _foo++; }
int _count; /// if there is something special to say
int _totalCount;
protected:
int _foo;
};
}
/**
* @brief This is the main function for the program
*/
int
main()
{
ts::Counter x;
if (x.getCount() == 0) {
x.increment();
} else {
// make sure to always use braces for conditionals
}
// increment the counter 10 times
for (int i = 0; i < 10; ++i) {
x.increment();
}
cout << x.getCount() << endl;
}
|
...
- Upper case for the first character of the name
- Use camel case (<nop>GoodClassName)GoodClassName)
Methods
- Use camel case for method names with the first charter being lower case (goodMethodName)
- Prepend '_' to the beginning of private or protected methods
Member Variables
- Prepend '_' at to the beginning of the private or protected member variable to distinguish it from other variablesvariable
Comments
TODO comments
Example of comment TODO:
...