0

The case is quite simple - we had a discussion based on experiencing some linker issues, where colleagues of mine were stating, that we are unable to access the static methods and variables that are declared and defined within the class, from other modules (dlls, libs, exe).

I believe it is not the case and this rule applies just for static global methods (if you do not export them manually), that are not visible, as the linker tries to persevere the ODR.

Who is correct, are static class methods/vars really invisible or this applies just for global statics?

CJ_Notned
  • 248
  • 2
  • 11
  • [Duplicate?](https://stackoverflow.com/q/15235526/10871073) – Adrian Mole Jul 18 '23 at 08:18
  • They are accessible when exported correctly (dllexport on windows). However exporting static member variables (globals) do come with their own initialization issues. So I would not recommend doing that. – Pepijn Kramer Jul 18 '23 at 08:22
  • @PepijnKramer: Yep, but that is the case of the global ones (that you need to alter the visibility rules for linker), with the ones declared within class you do not need to perform any exporting magic I believe. – CJ_Notned Jul 18 '23 at 08:25
  • 1
    There can be problems with inline static methods accessing static member variable. See [so](https://stackoverflow.com/questions/2479784/exporting-static-data-in-a-dll), the accepted answer and some other answers. Making the method not inline or giving it its own dllexport/dllimport attribute (in addition to common class-level dllexport) helps in most of the cases. – Mike Tyukanov Jul 18 '23 at 19:28

0 Answers0