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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -