The information in this article applies to:
SYMPTOMSCode that makes use of the C++ implicit invocation of a user-defined conversion causes the C/C++ compiler to generate the following error message: C/C++ 9.00 gives the following level 2 warning and errors from the implicit cast and only the warning from the explicit call:
RESOLUTIONExplicitly invoke the user-defined conversion, as demonstrated in the sample code in the "MORE INFORMATION" section below, rather then depending on the implicit invocation. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATIONSuppose a virtual-base class A is defined and classes B and C inherit from class A. Furthermore, a class E inherits from both B and C. The two classes, A and B, each provide a virtual user-defined conversion function to "int". The relationship may be represented by the following directed acyclic graph:
The dominance rule requires that when you invoke the virtual user-defined
conversion function to int from an instance of an object of type E, the
version provided by B should be used. This conversion function may be
invoked implicitly by assigning an instance of an object of type E to an
int. It may also be invoked explicitly through the use of the "operator
int" function.
As demonstrated by the following sample code, the compiler accurately identifies and invokes the correct user-defined conversion function when using the explicit call syntax. However, when attempting to make use of the implicit conversion, the compiler produces an error, citing an ambiguity in its search for the correct user-defined conversion function. Sample Code
REFERENCESThe Annotated C++ Reference Manual (ARM), Ellis and Stroustrup, section 10.1.1, "Ambiguities," section 10.2, "Virtual Functions," and section 12.3, "Conversions." Additional query words: kbVC400bug 8.00 8.00c 9.00
Keywords : kbCompiler kbCPPonly kbVC kbVC100bug kbVC150bug kbVC200bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug |
Last Reviewed: February 2, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |