mirror of
https://github.com/cpp-best-practices/cppbestpractices.git
synced 2025-12-17 11:14:35 +03:00
better examples for passing values for safety
Address comments from #37
This commit is contained in:
@@ -9,18 +9,8 @@
|
|||||||
class MyClass
|
class MyClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyClass(std::string t_value)
|
void do_something(int i);
|
||||||
: m_value(t_value)
|
void do_something(std::string str);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_value()
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -28,19 +18,10 @@ private:
|
|||||||
class MyClass
|
class MyClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyClass(const std::string &t_value)
|
void do_something(const int i);
|
||||||
: m_value(t_value)
|
void do_something(const std::string &str);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_value() const
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Consider Return By Value for Mutable Data, `const &` for Immutable
|
### Consider Return By Value for Mutable Data, `const &` for Immutable
|
||||||
|
|||||||
Reference in New Issue
Block a user