Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! squash! doc: formalize non-const reference usage in C++ style …
…guide
  • Loading branch information
addaleax committed Oct 1, 2018
commit e9f84067b623a056faa8ddb43290754450df1b09
7 changes: 5 additions & 2 deletions CPP_STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ assignment. A pointer is almost always a better choice.
```c++
class ExampleClass {
public:
explicit ExampleClass(int* int_ptr) : pointer_to_integer_(int_ptr) {}
explicit ExampleClass(OtherClass* other_ptr) : pointer_to_other_(other_ptr) {}

void SomeMethod(const std::string& input_param,
std::string* in_out_param); // Pointer instead of reference
Expand All @@ -230,7 +230,10 @@ class ExampleClass {

private:
std::string foo_string_;
int* pointer_to_integer_; // Pointer instead of reference.
// Pointer instead of reference. If this objects 'owns' the other object,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: object

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye Thanks for catching, done!

// this should be be a `std::unique_ptr<OtherClass>`; a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: double be

// `std::shared_ptr<OtherClass>` can also be a better choice.
OtherClass* pointer_to_other_;
};
```

Expand Down