Static variables in static method in base class and inheritance

前端 未结 6 1060
南方客
南方客 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 12:06

    There will only be one, shared by all three classes. If you want separate instances, you will have to create separate functions in the derived classes.

提交回复
热议问题