c++
#include <iostream>
using namespace std;
class GfG {
public:
static int x;
GfG() {
x++;
}
// static member function
// static void printMsg() { cout << "Welcome to GfG!" << x; }
};
int GfG::x = 3; // just like static member function
// main function
int main()
{
GfG obj1;
cout << obj1.x << endl;
obj1.x++;
GfG obj2;
cout << obj2.x << endl;
// invoking a static member function
// GfG::printMsg();
}
Enjoy Reading This Article?
Here are some more articles you might like to read next: