// The static member function indirectly accesses non-static data members.
// Static member functions can directly reference static data members and static member functions of the class, but cannot
// Directly reference non-static data members and non-static member functions; otherwise, an error is returned during compilation.
// If You Want To reference an object, you must pass the parameter to obtain the object name, and then use the object name to reference it.
# Include <iostream>
Using namespace STD;
Classmyclass
{
PRIVATE:
Intm; // non-static data member
Staticintn; // static data member
Public:
Myclass (); // Constructor
Staticintgetn (myclass A); // static member function
};
Myclass: myclass ()
{
M = 10;
}
Intmyclass: getn (myclass)
{
Cout <a. m <Endl; // indirectly uses non-static data members through the class
Return N; // directly use static data members
}
Intmyclass: N = 100; // static data member Initialization
Voidmain ()
{
Myclass app1;
Cout <app1.getn (app1) <Endl; // reference a static function member using an object
Cout <myclass: getn (app1) <Endl; // reference a static function member using the class name
}