Why won't my C++ program link when my class has static members?

后端 未结 5 1960
长情又很酷
长情又很酷 2021-01-18 04:55

I have a little class called Stuff that I want to store things in. These things are a list of type int. Throughout my code in whatever classes I use I want to be able to a

5条回答
  •  Happy的楠姐
    2021-01-18 05:05

    Static data members have to be defined outside class declarations, much like methods.

    For example:

    class X {
        public:
            static int i;
    };
    

    Must also have the following:

    int X::i = 0; // definition outside class declaration
    

提交回复
热议问题