Skip to content

Commit e9f8406

Browse files
committed
fixup! squash! doc: formalize non-const reference usage in C++ style guide
1 parent 8daa18e commit e9f8406

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

CPP_STYLE_GUIDE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ assignment. A pointer is almost always a better choice.
209209
```c++
210210
class ExampleClass {
211211
public:
212-
explicit ExampleClass(int* int_ptr) : pointer_to_integer_(int_ptr) {}
212+
explicit ExampleClass(OtherClass* other_ptr) : pointer_to_other_(other_ptr) {}
213213
214214
void SomeMethod(const std::string& input_param,
215215
std::string* in_out_param); // Pointer instead of reference
@@ -230,7 +230,10 @@ class ExampleClass {
230230
231231
private:
232232
std::string foo_string_;
233-
int* pointer_to_integer_; // Pointer instead of reference.
233+
// Pointer instead of reference. If this objects 'owns' the other object,
234+
// this should be be a `std::unique_ptr<OtherClass>`; a
235+
// `std::shared_ptr<OtherClass>` can also be a better choice.
236+
OtherClass* pointer_to_other_;
234237
};
235238
```
236239

0 commit comments

Comments
 (0)