Hello
I have a simple question.
Suppose I have:
How do you professionals return string by reference this way (const - so that it cannot be modified inside the function)?Code:class someclass {
public:
int &number() const { return m_number; } //this is okay
std::string &str() const { return m_str; } //this aint okay
private:
int m_number;
std::string m_str;
};
Should I just do:instead?Code:std::string &str() { return m_str; }
Thanks for help!