[R-pkg-devel] Function Overloading of S4 Methods

Linus Chen ||nu@@|@chen @end|ng |rom gm@||@com
Sat May 18 11:28:17 CEST 2019


Dear Dario,

I think differently, I think my examples show the resemblance between
the way of "dispatching" for S4 generic and that for C++ overloaded
function.
Both are dispatched ONLY through the type of arguments.

Again following your original example:
int larger(int x, int y);
char larger(char first, char second);
char larger(char x, char y){ # This will work!
if y>x y else x;
}
x = 'a' ; b='b';
larger(x,y);  # this will still call the second function.

The declaration "char largerChar(char first, char second);" does not
make any constraint on the name of argument...

Hope this helps.

Best,
Lei Chen

On Sat, May 18, 2019 at 10:00 AM Dario Strbenac
<dstr7320 using uni.sydney.edu.au> wrote:
>
> Good day,
>
> Your conclusion seems to be different to the details you discussed. Don't you intend to conclude that it's not possible with an S4 generic to define methods with different argument names which is different to a language such as C++?
>
> --------------------------------------
> Dario Strbenac
> University of Sydney
> Camperdown NSW 2050
> Australia
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list