Compiler error CS0563, Overload Operation+ (c#) | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Compiler error CS0563, Overload Operation+ (c#)

Please help me fix this error. My code looks like this: public class SquareMatrix<T> { //...some code public static SquareMatrix<int> operator +(SquareMatrix<int> a, SquareMatrix<int> b) { return a+b; } } //...some code class Program { static void Main(string[] args) { SquareMatrix<int> a = new SquareMatrix<int>(); SquareMatrix<int>.Size = 5; SquareMatrix<int>.FillAuto(a); Console.WriteLine(); SquareMatrix<int> b = new SquareMatrix<int>(); SquareMatrix<int>.FillAuto(b); Console.WriteLine(); SquareMatrix<int> c = a + b; //c = a - b; //c = a * b; //c = a / b; Console.WriteLine(); Console.ReadLine(); } }

7th Mar 2022, 11:53 AM
Nasibullo Khalilov
1 ответ
+ 1
Problem should be in: return a + b; You overloaded the + operation, so you're supposed to specify how you can add the classes together. But looks like you still added the classes to eachother. Hence, you should specify how it should add them. Does "a + b" mean a property "Row" in SquareMatrix "a" be added to property "Row" in SquareMatrix "b" to give a new SquareMatrix "c"?. How should the classes be added?. Specify it inside the overload.
30th Mar 2022, 11:49 PM
Sulaymahn
Sulaymahn - avatar