考虑以下内容:
如何解决上述问题,以便
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
都可以重载+
运算符,并将它们相加。