Microsoft KB Archive/324042

= FIX: Conversion to System:Object May Result in C2594 Ambiguity Error Message =

Article ID: 324042

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q324042



SYMPTOMS
When you try to convert a pointer to a managed object to System::Object *, you may receive the following error message from the compiler:

error C2594: 'initializing' : ambiguous conversions from ' ::Derived __gc *' to 'System::Object __gc *'



CAUSE
This behavior occurs when the following two conditions are true:
 * The managed pointer is of a class that derives from a class named Object.

-and-
 * Precompiled header options are turned on.

In this situation, the compiler cannot distinguish between the System::Object and the base Object class, so the compiler incorrectly issues the C2594 error.



RESOLUTION
To work around the problem, rename the base class to something other than Object.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).



MORE INFORMATION
The following code demonstrates the problem: //stdafx.h //include file for standard system include files

//stdafx.cpp //Compiler option required: /Yc &quot;Stdafx.h&quot; /clr
 * 1) include &quot;stdafx.h&quot;

//test.cpp //Compiler option required: /Yu &quot;stdafx.h&quot; /clr
 * 1) include &quot;stdafx.h&quot;
 * 2) using 

using namespace System;

namespace NS { public __gc class Object {   };    public __gc class Derived : public NS::Object {   }; }

int main(void) {   NS::Derived __gc* b = new NS::Derived; System::Object * p = (b);

return 0; }

Keywords: kberrmsg kbbug kbfix kbpending kbcompiler kbmanaged KB324042

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.