Home > Uncategorized > Static class members

Static class members

March 18th, 2009

#include “stdafx.h”
#include <iostream>
#include <iomanip>
using namespace std;

class test{
public:
void hi(){
static int i=0;
cout << i++<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
test A;
test B;

A.hi(); //prints 0
A.hi();// prints 1
B.hi();// prints 2
int x;
cin >>x;
return 0;
}

Sam Uncategorized

  1. No comments yet.
  1. No trackbacks yet.