PRB: C2440 When Initializing an Object Within an Object
Article ID: 121888
Article Last Modified on 12/1/2003
APPLIES TO
- Microsoft Visual C++ 1.0 Professional Edition
- Microsoft Visual C++ 1.5 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 Enterprise Edition
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 4.2 Professional Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
This article was previously published under Q121888
SYMPTOMS
If an object is used to initialize an embedded structure, the compiler
produces error C2440: 'initializing': cannot convert from '<type1> ' to
'<type2> '.
CAUSE
This behavior is by design. Although an aggregate that is a class may be
initialized with an object of its class, there is not a similar provision
for subaggregates.
RESOLUTION
To work around this behavior, use a member by member initialization.
Additional query words: 8.00 8.00c 9.00 10.00 11.00
Keywords: kbprb kbcpponly kbcompiler KB121888