1,072
edits
m (→references) |
m (Better example for const reference usage) |
||
Line 219: | Line 219: | ||
|- | |- | ||
| <syntaxhighlight lang="c++"> | | <syntaxhighlight lang="c++"> | ||
void foo (const | void foo (const std::string& str_ref) | ||
{ | { | ||
// foo does not change content of ` | // foo does not change content of `str_ref` | ||
} | } | ||
void bar () | void bar () | ||
{ | { | ||
std::string str ("This is a large variable, however as a reference it will take up just 8 bytes on the stack when passed to the subroutine foo()"); | |||
foo ( | foo (str); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| <syntaxhighlight lang="c++"> | | <syntaxhighlight lang="c++"> | ||
void foo ( | void foo (std::string str_copy) | ||
{ | { | ||
// foo does not change content of ` | // foo does not change content of `str_copy` | ||
} | } | ||
void bar () | void bar () | ||
{ | { | ||
std::string str ("This is a large variable that will be copied on to the stack and passed as a temporary variable to the subroutine foo()"); | |||
foo ( | foo (str); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
edits