my question is that when we use static data member and ststic function and nobody can not satisfy me about this question i need actual reason of using the static data member and ststic member function
moaz.amin.37 -12 Junior Poster
Recommended Answers
Jump to PostA static data member belongs to the class rather than to an individual instance of the class. Likewise with a static member function. A reasonable way to think about them at a high level is to treat the class as acting like a namespace for those members:
Jump to PostHere you go few examples of using static members:
#include <iostream> using namespace std; class MyClass{ static int counter; public: void print(int& i){ cout << "Number of instances: " << counter << endl; } MyClass(){ print(++counter); } ~MyClass(){ print(--counter); } }; int MyClass::counter = 0; // Static …
All 6 Replies
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Kristian_2 11 Light Poster
Kristian_2 11 Light Poster
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
Kristian_2 11 Light Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.