ccplusplus.com
Learn C, C++ Concepts
Monday, December 19, 2011
static member functions
/******************************************************* * File : static-member-Function.cpp * Author : Saurabh Gupta * Description : static member Function example c++ * Date : PM 10:33 19 December 2011 * Source : http://www.ccplusplus.com/p/c_15.html * Note : *******************************************************/ #include
using namespace std; class CStatic { private: static int s_nStaticMember; public: CStatic(); ~CStatic(); static int m_Show() { return s_nStaticMember ++; } }; int CStatic::s_nStaticMember = 1; CStatic :: CStatic() { } CStatic :: ~CStatic() { } int main() { for (int i = 0; i < 5; i++) { cout << "Static variable at the moment is : " << CStatic :: m_Show() << endl; } return 0; } /* * OUTPUT * [sgupta@rhel6x64 19122011]$ c++ -o static-member-Function static-member-Function.cpp [sgupta@rhel6x64 19122011]$ ./static-member-Function Static variable at the moment is : 1 Static variable at the moment is : 2 Static variable at the moment is : 3 Static variable at the moment is : 4 Static variable at the moment is : 5 [sgupta@rhel6x64 19122011]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment