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/

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JerryCheng 的頭像
    JerryCheng

    KwCheng's blog

    JerryCheng 發表在 痞客邦 留言(0) 人氣()