+ Reply to Thread
Results 1 to 2 of 2

Thread: What is static member function of a class?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    48

    What is static member function of a class?

    What is static member function of a class?

    How to use class member in static member function of a class?

    Provide me example.

  2. #2
    'static' member function of a class means you can use that procedure without creating an object of that class!

    Note:
    You can access only static data member from the static member function.

    Code:
    //header file...
    class CLogging
    {
    	static int m_nLoggingLevel ;
    	public:
    		static void DoLogging()
    		{
    			if (m_nLoggingLevel > 1)
    			{
    				//Do something...
    			}
    			else
    			{
    				//Do something...
    			}
    		}
    } ;
    
    //source file, initialize the static data member here.
    int CLogging::m_nLoggingLevel = 0;
    
    void UseStaticMember()
    {
    	CLogging::UseStaticMember() ;
    }
    Note:
    Please note that you will need to initialize the static data member with the defaults in the source file.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts