c++ - When is a non-static const data member more useful than a const static one? -
in c++ there static , non-static const
data members. when want constant, make static
because not make sense have multiple copies (one per each instance of class) if item cannot modified. know why there non-static const
members?
- a
static const
applies class - a
const
applies object
e.g.
class verticies { public: const int colour; static const int max_verticies = 100; point points[max_verticies]; verticies(int c) : colour(c) { } // etc };
here max_verticies
applies objects of type verticies
. different objects have different colours , colour fixed on construction
Comments
Post a Comment