today, for the sake of brevity of the code, a class Msghelper is used to define static member variables and static member functions.
At the beginning, my writing is (not real code, just an example):
<strong>class helper{static int index;static void sendmsg (Tcpsocket *&,string &);};static int helper:: index=1;static void Helper::sendmsg (Tcpsocket * &sock,string &msg) {if (!sock | | Msg.length () ==0) return;sock->write (MSG); return;} </strong>
Even compile the error, and later corrected to:
<strong>class helper{static int index;static void sendmsg (Tcpsocket *&,string &);}; int helper::index=1; void Helper::sendmsg (Tcpsocket * &sock,string &msg) {if (!sock | | Msg.length () ==0) return;sock->write (MSG); return;} </strong>
That is, static member functions or variables are defined outside the class body to remove the static identifier;
Note: You can initialize in a class only if the static member variable type in the class is normally shaped, such as:
Class simple_string{static const int length=1;static char str[length + 1];}; Char simple_string::str[length +1]= "Default string";
Other types, even if declared as const types, cannot be initialized in a static class.
C + + static variables and static member functions of the strange temper