#Problems with inlining and C++11 incompatibility

8 messages · Page 1 of 1 (latest)

wild swan
#

I have this code here in the private section of my struct:

static inline std::map<sv, u8> scoreboard {
  { "test1", 0 },
  { "test2", 1 },
  // you get the point
};

This works completely fine, but I'm currently making a C++ library with the intention to work for C++11. But when i compile with that C++ standard, it issues a warning about "inline variables are a C++17 extension". So I tried removing the inline keyword, and now it gives me an error saying: "non-const static data member must be initialized out of line".

I have absolutely no idea what that means or what I should do to fix this. If anybody could give me a hand then that would be greatly appreciated.

exotic owlBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wild swan
#

for example:

#

;compile c++ -std=c++11

#include <bits/stdc++.h>

struct test {
private:
  static inline std::map<const char*, std::uint8_t> map_example {
    { "test1", 0 },
    { "test2", 0 }
  };

public:
  static void add() {
    map_example["test1"] = 1;
  }
};

int main() {
  test::add();
  return 0;
}
devout graniteBOT
#
Compiler Output
<source>:5:10: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
    5 |   static inline std::map<const char*, std::uint8_t> map_example {
      |          ^~~~~~
wild swan
#

TL;DR i just need to find a way to get rid of this warning

#

solved my issue, i just had to define the variable outside of the struct with a declaration within a struct

#

!solved