Static Members of a Class/Structure
Static Data Members
static storage class modifier.class_name::variable.:: is used for access.**Example (CParser):**
class CParser { public: static int s_words; static int s_symbols; };
int CParser::s_words = 0;
int CParser::s_symbols = 0;
Static const Data Members
const keyword.const keyword.**Example (CStack):**
class CStack { private: static const int s_max_length; };
const int CStack::s_max_length = 1000;
Pointer this
this.Static Methods
static modifier before the return type within the class.**Example (CStack::Capacity):**
class CStack { public: static int Capacity(); };
int CStack::Capacity(void) { return(s_max_length); }
**Accessing Static Methods:**
object.static_method()ClassName::static_method()const Correctness
const modifier placed after the argument list in declaration and definition.const as they don't operate on an instance.**Example (CRectangle::Square):**
class CRectangle { public: double Square(void) const; };
double CRectangle::Square(void) const { return(Square(m_width,m_height)); }
Optimization
const objects by placing them in read-only memory.
Previous
arrow_back
Virtual functions