What is the function to do? Scratch that, if the function operates on the class and not an instance object of the class, then make the function static.
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
class X
{
private:
int i;
staticint si;
public:
void set_i(int arg) { i = arg; }
staticvoid set_si(int arg) { si = arg; }
void print_i() {
cout << "Value of i = " << i << endl;
cout << "Again, value of i = " << this->i << endl;
}
staticvoid print_si() {
cout << "Value of si = " << si << endl;
}
};
int X::si = 77; // Initialize static data member
int main()
{
X xobj;
xobj.set_i(11);
xobj.print_i();
// static data members and functions belong to the class and
// can be accessed without using an object of class X
X::print_si();
X::set_si(22);
X::print_si();
}