Reaching static variables in C++ -
if define static variable in classa:
static int m_val; and initialize
int classa::m_val = 0; can use directly m_val in order access in classa (or other class) or should use classa::m_val.
inside of classa, write m_val. outside of classa, classa::m_val.
however, m_val not const in example, (typically) should private anyway. in case, you'd not access directly other classes provide member function retrieve copy:
class classa { private: static int m_val; // ... public: static int getval(); }; implementation:
int classa::m_val = 0; int classa::getval() { return m_val; }
Comments
Post a Comment