Static variables in instance methods

前端 未结 5 1644

Let\'s say I have this program:

class Foo {
 public:
    unsigned int bar () {
        static unsigned int counter = 0;
        return counter++;
    }
};

int m         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 03:35

    From The C++ Programming Language (2nd edition), page 200, by Bjarne Stroustrup:

    Don't use static except inside [plain] functions (§7.1.2) and classes (§10.2.4).

提交回复
热议问题