【发布时间】:2016-05-26 13:51:38
【问题描述】:
考虑以下几点:
A = R6::R6Class("ClassA")
B = R6::R6Class("ClassB")
`+.ClassA` = function(o1,o2) o1 #Trivial Example, Usually do something
`+.ClassB` = function(o1,o2) o1 #Trivial Example, Usually do something
a = A$new()
b = B$new()
a + b
这会引发错误:
Warning: Incompatible methods ("+.ClassA", "+.ClassB") for "+"
Error in a + b : non-numeric argument to binary operator
上面的怎么解决,所以A和B都可以重载+操作符,相加。
【问题讨论】:
标签: r operator-keyword r6