0
Why is needed static in c++? How it works? Please, give example.
4 Antworten
+ 8
One of the uses of static variables is recursion base case evaluation.
void recur()
{
static int x = 0;
if (x < 10)
{
std::cout << "Recursing.\n";
++x; recur();
}
}
+ 6
static data members are just like global variable maintaining only one copy of the variable that are common to all the objects of the class. for eg,static data members can be used to keep track of existing objects.
0
en.cppreference.com/w/cpp/language/static
I guess they cover whole topic of static keyword ^^
0
@Await Tiwari, that is, if I declared static void f(), now I can't overload this function/method?