PRB: C2440 When Initializing an Object Within an Object (121888)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 4.0
- Microsoft Visual C++ 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.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 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.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbCompiler kbCPPonly kbprb KB121888 |
---|
|