• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About polymorphism

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone tell me why compiler show the following error message ?
"reference to m is ambiguous, both method m(B, B) in C and method m(A, C) in C match m(c, c)."

But if I change m(A x, C y) to m(B x, C y) will work properly.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question was just answered within the last few days.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll try, but I do not feel 100% that I understand it myself; so beware.
The compiler must try to decide which of m(B, B) or m(A, C) is "most specific" to the actual call which is type m(C, C). If we choose the m(B, B) case we can object because the second argument is a C, so m(A, C) is "more specific". If we choose the m(A, C) case we can object because the first argument is a C which is a B, so m(B, B) is "more specific". Because we can object in both cases it cannot be decided which of the two methods to call.
When you change the m(A, C) to m(B, C) we can choose m(B, C) because the second argument is a C which is more "specific" than it being a B.
Is there some easy algorithm for resolving these things?
-Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Thomas means here.
 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!
I think I got what you mean.
 
reply
    Bookmark Topic Watch Topic
  • New Topic