DEV Community


Posted on

Answer: How to initialize private static members in C++?

The class declaration should be in the header file (Or in the source file if not shared).
File: foo.h

class foo
        static int i;

But the initialization should be in source file.
File: foo.cpp

int foo::i = 0;

If the initialization is in the header file then…

Discussion (0)