Как определить статический член класса в функции? - PullRequest
0 голосов
/ 19 марта 2012

Здесь у меня есть:

class X {

public:
    static int shared_arr[];
    static void alloc_and_init() {

        // Since any static variables defined in the function are allocated some space.
        // So can I define X::shared_arr here (using the space the static variable for X::shared_arr)? 
        // I think it would be a convenient way to make an approach of some basic memory allocation and initialization.
    }

};

1 Ответ

2 голосов
/ 19 марта 2012

Нет, вам нужно будет определить его точно в одном файле cpp и вне любой функции.

int X::shared_arr[MAX_SIZE] = {0};
^^^

Обратите внимание, что вам не хватает типа массива.

...