Topic: Ambiguous conversion operators??


Author: tom@tom.mvision.com (TOM)
Date: Wed, 6 Oct 1993 19:35:27 GMT
Raw View
    The following section of code compiles under g++,
Zortech C++, and Sun's SunOS4 C++ compiler, but not under
Microsoft's C++.  Microsoft claims that there is no
standard that covers this problem, so they are free to do
what they want.

    The basic problem is that I have two overloaded
conversion operators in a class: one converts the class to a
char*, the other to a void*.  When I try to actually use the
void* conversion, the Microsoft compiler claims that the
conversion is ambiguous.

    Amusingly enough, the Sun cfront actually translates
both void* and char* into char*, yet it generates correct
code anyway.

    I have not yet found the spot in the Annotated Reference
Manual that makes it clear one way or the other who is
correct, or if there is a correct answer/

    Any suggestions?


    const void* NULL = (void*) 0L;

    class FRED {

      private:
        void*    v;
        char*    c;

      public:
        FRED( )          { v = NULL; c = ""; }
        operator char*() { return c; }
        operator void*() { return v; }
    };

    #define WANT_TO_FAIL

    void main()
    {
        FRED fred;
        char* joe = (char*) fred;           // Works everywhere.

    #ifdef WANT_TO_FAIL

        void* mike = (void*) fred;          // Fails under Microsoft.

    #else

        void* mike = fred.operator void*(); // Works everywhere.

    #endif
    }


    Thanks for your attention!

    /t

=====================================================================
Tom Ritchford   Market Vision
US Mail   40 Rector Street, NYC 10006
Internet  tom@mvision.com
Work Phone  (212) 227-1610
Home Phone  (718) 384-5716

Send your US mail address for a free subscription to
    "The Journal of Pataphysical Reviews"
--

    /t

=====================================================================
Tom Ritchford   Market Vision
US Mail   40 Rector Street, NYC 10006
Internet  tom@mvision.com
Work Phone  (212) 227-1610
Home Phone  (718) 384-5716

Send your US mail address for a free subscription to
    "The Journal of Pataphysical Reviews"