...
Code Block |
---|
const int kYouAreReadingThis{0} constexpr bool kNiceThanksForReading{false}; |
Pointers
The* should be separated on both sides by a spaceattached to the datatype:
Code Block | ||
---|---|---|
| ||
int * integer_pointer = nullptr; |
...
Code Block |
---|
bool isDone{false}; for (int i = 0; i < 10 && !isDone; i++) { if (6 == i) { isDone = true; } } |
continue
statements will be allowed, however they should only be used if it will simplify the code by a significant amount.
Functions
Naming and Brackets
...
Parameter names should follow the same conventions as written in the Variables
section.
Pointers
The* in pointers must be separated on both sides by one space.
Code Block | ||
---|---|---|
| ||
void hewwoThereFwend(string * fwend_name) { ... } |
NOTE: Moving forward, we will prefer to use reference parameters over pointers when passing by reference. It is a more C++ style of programming.
...
All function declarations must have a comment above describing its purpose, parameters, and returned value. Pay notice to the spacing on the* and the /**
that opens the comment
Code Block | ||
---|---|---|
| ||
/** * This function switches the friend's name with a new name * * @param fwend_name -> reference pointing to the friend's name * @param new_fwend_name -> value of the friend's new name * * @return none */ void switchFwendName(string& fwend_name, string new_fwend_name); |
...
Code Block | ||
---|---|---|
| ||
class ExampleClass {
public:
ExampleClass();
ExampleClass(int num_apple_pies);
private:
int apple_pies, banana_pies;
double slices_left;
}
ExampleClass::ExampleClass() : apple_pie {0}, banana_pies {0}, slices_left {0.0f} {}
// You can stack your initializing list. Just make sure they start in the same column
ExampleClass::ExampleClass(int num_apple_pies) : apple_pies {num_apple_pies},
banana_pies {0} {
slices_left = 6 * num_apple_pies; // If an operation is required, preferred if initialization is within constructor
} |
...
Code Block | ||
---|---|---|
| ||
class ExampleClass { ... }; int main() { ExampleClass * example_pointer = nullptr; // Good! ExampleClass statically_declared_class {}; ExampleClass * other_pointer = &statically_declared_class; // Also good! ExampleClass * one_more_pointer = functionThatReturnsAClassPointer(); // Good too! } |
...
Code Block | ||
---|---|---|
| ||
StructName * struct_variable = nullptr; StructName * struct_variable_two = functionThatReturnsAStructNamePointer(); // Valid too! |
...