+ Reply to Thread
Results 1 to 2 of 2

Thread: What is static data member of a class?

  1. #1

    What is static data member of a class?

    Hi,

    What is static data member of a class?

    What is its usage?

    Regards.

  2. #2
    Hi,

    Properties of the static member of a class:
    Static member can be const and volatile.
    Static members exist even if object of that class does not exist.
    Modifiers (private, protected, public) is also applicable to static members of a class.

    Example:

    Code:
    class CObjectCounter
    {
    private:
    	static int m_nObjectCounter ;
    
    public:
    	CObjectCounter()
    	{
    		m_nObjectCounter++ ;
    		char szCounter[100] ;
    		sprintf(szCounter, "Object Count == %d\n", m_nObjectCounter) ;
    	}
    
    	~CObjectCounter()
    	{
    		m_nObjectCounter-- ;
    
    		char szCounter[100] ;
    		sprintf(szCounter, "Object Count == %d\n", m_nObjectCounter) ;
    	}
    } ;
    
    int CObjectCounter::m_nObjectCounter = 0 ;
    
    void UseObjectCounter()
    {
    	CObjectCounter objObjectCounter1 ;
    	{
    		CObjectCounter objObjectCounter2 ;
    		{
    			CObjectCounter objObjectCounter3 ;
    		}
    	}
    }
    Regards.

+ 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