Static variables in static method in base class and inheritance

前端 未结 6 1051
南方客
南方客 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 11:48

    If you are making X as static then it will be shared among all the child classes. No issues with the function being static.

提交回复
热议问题