Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > virtual fun ambiguous call?

Reply
Thread Tools

virtual fun ambiguous call?

 
 
Noah Roberts
Guest
Posts: n/a
 
      03-28-2011
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
 
Reply With Quote
 
 
 
 
Noah Roberts
Guest
Posts: n/a
 
      03-28-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT Thursday, uh, fun, yeah, fun! Consultant MCSE 17 02-10-2007 03:39 AM
3 PIX VPN questions - FUN FUN FUN frishack@gmail.com Cisco 3 03-16-2006 02:25 PM
OT: Wednesday follow-up-to-Tuesday-Fun Fun Ken Briscoe MCSE 0 07-14-2004 01:41 PM
Programming is not as much fun/more fun than it used to be. Andy Fish Java 65 05-18-2004 08:24 PM
Fun fun fun Luke Computer Support 3 10-07-2003 03:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57