declare it as static,
// static1.cpp
// compile with: /EHsc
#include %26lt;iostream%26gt;
using namespace std;
void showstat( int curr ) {
static int nStatic; // Value of nStatic is retained
// between each function call
nStatic += curr;
cout %26lt;%26lt; "nStatic is " %26lt;%26lt; nStatic %26lt;%26lt; endl;
}
int main() {
for ( int i = 0; i %26lt; 5; i++ )
showstat( i );
}
dogwood
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment