static member function
#include <iostream>
using namespace std;
class MyClass{
static int num;
int n;
public:
void set_n(){
n = ++num;
}
void display_n(){
cout<<"n : "<<n<<endl;
}
//static member function
static void display_num(){
cout<<"num : "<<num<<endl;
}
};
int MyClass:: num;
int main()
{
MyClass e1, e2;
e1.set_n();
e2.set_n();
e1.display_n();
e2.display_n();
MyClass::display_num();
return 0;
}
Comments
Leave a comment