Article ID: 117383
Article Last Modified on 7/5/2005
APPLIES TO
- Microsoft Visual C++ 1.0 Professional Edition
- Microsoft Visual C++ 2.0 Professional Edition
- Microsoft Visual C++ 4.0 Standard Edition
- Microsoft Visual C++ 4.1 Subscription
- Microsoft Visual C++ 4.2 Professional Edition
- Microsoft Visual C++ 5.0 Standard Edition
- Microsoft Visual C++ 6.0 Service Pack 5
- Microsoft Visual C++ .NET 2002 Standard Edition
- Microsoft Visual C++ .NET 2003 Standard Edition
This article was previously published under Q117383
SYMPTOMS
Instantiating a C++ object with the thread attribute generates the following error message if the class contains private or protected members:
To paraphrase page 397 of the "C++ Language Reference," class objects may be instantiated with the thread attribute if the objects do not need to be constructed or destructed. However, this error occurs even though the class does not have a constructor or a destructor.
CAUSE
Currently, thread local storage has only been implemented for aggregate types. An aggregate type is defined as an array or object of a class with no constructors, no private or protected members, no base classes, and no virtual functions. In this case, private or protected members make the class an aggregate; therefore, the error message is generated.
RESOLUTION
To avoid this error, make all private or protected members of the class public members.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
The sample code below demonstrates how to produce and avoid the error message. Uncomment the "public" keyword before the data member to avoid the error.
Sample Code
/* Compile options needed: /c /MT */ class B { // Uncomment the following line to eliminate compiler error // public: int i; }; __declspec(thread) B b; // error C2483
Additional query words: kbVC400bug 8.00 9.00
Keywords: kbbug kbcpponly kbcompiler KB117383