Given the following scenario, which one of the following is preferred. m_state is a member rater than a local variable.
class C
{
private:
double m_state;
public:
double state() const { return m_state; } // returns double
double& state() { return m_state; }
}
===========================================
class C
{
private:
double m_state;
public:
const double& state() const { return m_state; } // returns const double&
double& state() { return m_state; }
}