Static variables in static method in base class and inheritance

前端 未结 6 1055
南方客
南方客 2021-01-02 11:44

I have these C++ classes:

class Base
{
protected:
    static int method()
    {
        static int x = 0;
        return x++;
    }
};

class A : public Base         


        
6条回答
  •  萌比男神i
    2021-01-02 11:52

    The former. Local static variables are bound to the method containing them, and method exists in one incarnation for all subclasses (in fact, for the whole app, even though the rest of the program does not see the method).

提交回复
热议问题