close
Static member function means that we can be called directly by using the class name and the scope operator.
for example :
class
IDGenerator
{
private
:
static
int
s_nNextID;
public
:
static
int
GetNextID() {
return
s_nNextID++; }
};
// We'll start generating IDs at 1
int
IDGenerator::s_nNextID = 1;
int
main()
{
for
(
int
i=0; i < 5; i++)
cout <<
"The next ID is: "
<< IDGenerator::GetNextID() << endl;
return
0;
}
ref : http://www.learncpp.com/cpp-tutorial/812-static-member-functions/
全站熱搜