Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 1
    I think the proper syntax to avoid linker errors is static inline .... See here: static members. Commented Sep 7, 2023 at 12:15
  • This is related to the so called ODR-usage (to put it simple: taking address via pointer or reference) of a variable that is only declared, but not defined. Split definition and declaration or make the variable inline. See this: stackoverflow.com/questions/272900/… Commented Sep 7, 2023 at 12:18
  • Can't repro: godbolt.org/z/jfd6177sa you should provide more detail about build process. Commented Sep 7, 2023 at 12:53
  • I now see here, that static constexpr int i = 10; should imply inline and is therefore a definition (not only a declaration). So there should be no linker error. That's from c++17. Which version of c++ do you use ? Commented Sep 7, 2023 at 13:32
  • 1
    @one_two_three still the rule about static class member still applies, see stackoverflow.com/a/28446388/4885321 Note: "The member shall still be defined in a namespace scope if it is odr-used" Commented Sep 7, 2023 at 14:47