Static Members in C++ classes
Tags:
cpp
oop
If we want to keep a data member or member function commonly accessible to all objects of the class (without being compiled separately for each object), we can make them static
Consider below example for computing the Nth Padovan number in this GFG question. We pre-compute the ans
vector only once and use that commonly for all objects of Solution
class
Static member variables must be defined outside of the class definition to allocate memory for them. Notice the
vector<int> Solution::ans;
line