0

i have c++ header file where i declarate static function and then when i run it through my c++ file it outputs undefined reference, why is that? code :

class GC{
static void* blocks[5];
static size_t available_space[5];
static size_t blockscount;
public:
    static void initialize();
};

and this is the cpp file:

    #include<iostream>
    #include "gc.hh"

    using namespace std;
    void GC::initialize(){
        GC::blocks[0] = malloc(1024);
        GC::available_space[0] = 1024;
        GC::blockscount = 1;
    }

my errors a re : undefined reference to GC::blockscount and so on

  • 1
    Also: [https://stackoverflow.com/questions/16284629/undefined-reference-to-static-variable-c](https://stackoverflow.com/questions/16284629/undefined-reference-to-static-variable-c) – drescherjm Dec 12 '21 at 16:23

0 Answers0