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
|
||||
{
|
||||
public:
|
||||
MyClass(std::string t_value)
|
||||
: m_value(t_value)
|
||||
{
|
||||
}
|
||||
|
||||
std::string get_value()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
void do_something(int i);
|
||||
void do_something(std::string str);
|
||||
};
|
||||
|
||||
|
||||
@@ -28,19 +18,10 @@ private:
|
||||
class MyClass
|
||||
{
|
||||
public:
|
||||
MyClass(const std::string &t_value)
|
||||
: m_value(t_value)
|
||||
{
|
||||
}
|
||||
|
||||
std::string get_value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
void do_something(const int i);
|
||||
void do_something(const std::string &str);
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Consider Return By Value for Mutable Data, `const &` for Immutable
|
||||
|
||||
Reference in New Issue
Block a user