Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22059

How to use a static member-struct in multiple source files? [closed]

$
0
0

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?


Viewing all articles
Browse latest Browse all 22059

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>