<<< Scope pitfalls | Index | Static member functions >>> |
Class members may be declared static
Static data members belong to the class, not to any object...
...so they don't take up space in objects.
All objects share static variables just like global variables, but in the class scope:
// point.h class Point { static int x_origin; static int y_origin; int m_x; int m_y; //... }; // point.cpp: int Point::x_origin = 0; // initialization of private (!) static members int Point::y_origin = 0;
<<< Scope pitfalls | Index | Static member functions >>> |