Exporting static class members

  • Thread starter Thread starter xprogrammer
  • Start date Start date
X

xprogrammer

Guest
Hello,
I have a class that is exported from a DLL and has a static member:

class __declspec( dllexport ) MyClass

{
public:
MyClass();
static int CONSTANT;
};


The implementation of the class is in a separate cpp file:

#include "MyClass.h"

int MyClass::CONSTANT = 0;

MyClass::MyClass() { }


I try to use the class and the exported static member from a function in another project:

#include "MyClass.h"
int main()
{
MyClass a;
int i = MyClass::CONSTANT;
}


But when I try to build my solution I get a link error:
main.obj : error LNK2001: unresolved external symbol "public: static int MyClass::CONSTANT" (?CONSTANT@MyClass@@2HA)

I can use other members or methods in the class. Is there something special I need to be able to link the static members? I checked the lib with dumpbin and I see the static member in the list of exported items.

Thanks.


Continue reading...
 
Back
Top