Попробуйте определить методы внутри класса дела
case class Complex(real: Double, imaginary: Double) {
def +(c2: Complex): Complex = Complex(real + c2.real, imaginary + c2.imaginary)
def add(c2: Complex): Complex = this + c2
}
или определить методы расширения, если у вас нет доступа к классу дела
case class Complex(real: Double, imaginary: Double)
implicit class ComplexOps(c1: Complex) {
def +(c2: Complex): Complex = Complex(c1.real + c2.real, c1.imaginary + c2.imaginary)
def add(c2: Complex): Complex = c1 + c2
}
или исправить метод add
вобъект
case class Complex(real: Double, imaginary: Double)
object Complex {
def +(c1: Complex, c2: Complex): Complex = Complex(c1.real + c2.real, c1.imaginary + c2.imaginary)
def add(c1: Complex, c2: Complex): Complex = Complex.+(c1, c2)
}