mercredi 20 septembre 2023

How do we define static member variables in header only projects? [duplicate]

I am using C++11.

Usually, we define static members as follows:

my_static.hpp:

class MyClass
{
public:
    static double MyStaticVar;
};

my_static.cpp:

double::MyClass MyStaticVar = 100.001;

Say I have a static library where all files are header-only *.hpp files.

Suppose I don't want to use any *.cpp files. I only want to use *.hpp header files.

Then how do you define a static member variable?

Aucun commentaire:

Enregistrer un commentaire