Static Data Members

#include <iostream.h>
/************************************************************
 File: static_class.C
 This program demonstrates how static data members are 
 handled
************************************************************/
 
class Test{
public:
	static int x;
	Test(void) {
		cout << "Objects created = " << ++x << "\n";
	}
};

int Test::x = 0; // Initialize the static member here

int main() {
	Test ob1, ob2;
	
	cout << "Test::x = " << Test::x << endl;

	return(0);
}	

Output:
Objects created = 1
Objects created = 2
Test::x = 2




Back to Previous Page

Document:
Local Date:
Last Modified On: