Re: polymorphism/boxing question



<lorenzon@xxxxxxxxx> wrote:
quick update by self:
after looking into it it almost seems like this is impossible as I
read that C# determines which overload to invoke for a given call at
compile time. This seems to me to be lame, and kind of hobbles
polymorphism doesn't it? At least I should be able to unbox my
variable from its generic interface type and have the call made on it
then.

Okay, to start with: there's no boxing involved in your examples.
Boxing is a matter of representing a value type value as a reference
type instance. You haven't shown any value types being involved at all.

And yes, you're right: overloading is performed at compile time. That
doesn't hobble polymorphism, however, which is more about *overriding*
than overloading.

"Double dispatch" may be the answer to your issues, however. See
http://en.wikipedia.org/wiki/Double_dispatch

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Function Overloading
    ... There can be some nasty "ambiguous overloading" bugs. ... It's usually some overhead at run-time (although this point may ... Overloading is fully resolved at compile time. ... overload resolution rules -- although it is never totally ...
    (comp.lang.c)
  • Re: optional argument versus subroutine overloading
    ... Overloading is typically resolved at compile time. ... subroutine call at all. ... wouldn't repeat the test in the middle of a time critical loop inside of ...
    (comp.lang.fortran)
  • Re: Equals() and inheritance
    ... The overloaded Equals() for object of type B is ... You're confusing overloading and overriding. ... but overloading is performed at compile time. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Python syntax in Lisp and Scheme
    ... but overloading only works at compile time: ... > doesn't work if you're using a base class pointer for all your derived ... I think that the point was that the overload resolution rules can handle the ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... >> compiles and runs without complaint. ... > Ahh, but overloading only works at compile time: ...
    (comp.lang.python)