c++ - Are all variables inside a static function static by default? -
static void foo() { int bar = 0; } is bar static default? standard this?
no, provision making variable static in c++ static keyword.
for example if change foo to:
static void foo() { int bar = 0; bar++; cout << bar << endl; } and call:
foo(); foo(); because bar not static output be:
1
1
if declare bar static this:
static void foo() { static int bar = 0; bar++; cout << bar << endl; } your output in fact be:
1
2
Comments
Post a Comment