BUG: C2487 Error Occurs If Multiple Static Vars Use dllexport

This article was previously published under Q127900
This article has been archived. It is offered "as is" and will no longer be updated.
SYMPTOMS
Using _declspec(dllexport) or _declspec(dllimport) on a class with multiplestatic variable definitions may cause a C2487 error to be generated on allbut 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 aboveclass 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.
kbVC400bug dllimport export afxdll 9.00 9.10 10.00 10.10 10.20
Properties

Article ID: 127900 - Last Review: 01/11/2015 00:57:06 - Revision: 1.1

  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • kbnosurvey kbarchive kbbug kblangcpp KB127900
Feedback