I need to use a struct, that is a static member of my class, in multiple source files. Here's a trimmed down example:
Header File
namespace NS {
class Foo {
public:
static struct Bar {
bool test = false;
uint32_t value; // uninitialized
} bar;
};
}
Source File 1
#include "myHeader.hpp"
using namespace NS;
Foo::Bar Foo::bar;
/* the rest of my first source file */
This seems to work without any problems until I add a second source file.
Source File 2
#include "myHeader.hpp"
using namespace NS;
Foo::Bar Foo::bar;
/* the rest of my second source file */
Upon adding the struct to the second source file, I get a "multiple definition" error. Does anyone know how to make this work, so that a static member-struct can be used in multiple source files?