virtual fun ambiguous call?

Discussion in 'C++' started by Noah Roberts, Mar 28, 2011.

  1. Noah Roberts

    Noah Roberts Guest

    I always thought that f(type0) and f(type1) would resolve to different
    function calls when the two parameter types are unrelated. I've run
    into a situation where that's definitely come into doubt.

    Consider:

    struct type0 {};
    struct type1 {};

    struct base0 { virtual int get(type0) const = 0; };
    struct base1 { virtual double get(type1) const = 0; };

    struct test_object_ : base0,base1 {};
    struct test_object : test_object_
    {
    int get(type0) const { return 5; }
    double get(type1) const { return 42.666; }
    };

    int main()
    {
    test_object o;
    test_object_ * op = &o;

    int x = o.get(type0()); // OK by both VS2010 and Comeau
    int y = op->get(type0()); // ambiguous call to get in both.
    }

    After the ambiguous call error I also get an error about not being able
    to convert type0 to type1 when using VS2010.

    I realize name resolution happens earlier than parameter resolution so
    both get() functions are viable names before the type is applied, but
    once type is applied get(type1) should become non-viable and be
    discarded. This isn't happening through the pointer even though both
    the pointer and the static type have the same set of functions.

    Can anyone explain why this is so?

    --
    http://crazycpp.wordpress.com
     
    Noah Roberts, Mar 28, 2011
    #1
    1. Advertising

  2. Noah Roberts

    Noah Roberts Guest

    On 3/28/2011 10:12 AM, Noah Roberts wrote:

    > Can anyone explain why this is so?
    >


    I can. 10.2 explains how member name lookup works and if the name
    refers to members of unrelated sub-objects that are not hidden, the
    program is ill-formed. Parameter overload resolution can't then resolve
    ambiguity and there's an example showing such in 10.2/3.

    Boo.

    --
    http://crazycpp.wordpress.com
     
    Noah Roberts, Mar 28, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    65
    Views:
    1,765
    Mabden
    May 18, 2004
  2. ishekara

    ambiguous call to overloaded

    ishekara, Feb 25, 2005, in forum: C++
    Replies:
    7
    Views:
    6,512
    red floyd
    Feb 25, 2005
  3. Replies:
    5
    Views:
    354
    Pete Becker
    Mar 10, 2006
  4. dolphin
    Replies:
    4
    Views:
    323
    Jorgen Grahn
    Aug 25, 2007
  5. er
    Replies:
    2
    Views:
    509
Loading...

Share This Page