BUG: C2487 Error Occurs If Multiple Static Vars Use dllexport (127900)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Editions 2.0
  • Microsoft Visual C++, 32-bit Editions 2.1
  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Editions 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q127900

SYMPTOMS

Using _declspec(dllexport) or _declspec(dllimport) on a class with multiple static variable definitions may cause a C2487 error to be generated on all but the first variable. For example, consider this class declaration:
class _declspec(dllexport) MyClass
{
public:
static int i,j,k;
};
				
This class declaration generates these errors:
error C2487: 'j' : member of dll interface class may not be declared with dll interface

error C2487: 'k' : member of dll interface class may not be declared with dll interface

RESOLUTION

Move each static variable declaration to its own line. To fix the above class so that it will compile cleanly, use this:
class _declspec(dllexport) MyClass
{
public:
  static int i;
  static int j;
  static int k;
};
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbBug kbLangCPP KB127900