Как создать объект класса, если в нем реализована перегрузка? - C#
Формулировка задачи:
Есть код:
Как в нем создать объект? Не могу его создать ввиду того что он сразу воспринимается как метод класса. Как быть?
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace thevector
- {
- class Vector
- {
- double x, y, z;
- public Vector(double x, double z, double y)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public static Vector operator +(Vector a, Vector b)
- {
- Vector c = new Vector(a.x + b.x, a.y + b.y, a.z + b.z); //результирующий вектор
- return c;
- }
- public void setVectorPos()
- {
- Console.WriteLine("Enter x:");
- this.x = Int32.Parse(Console.ReadLine());
- Console.WriteLine("Enter y:");
- this.y = Int32.Parse(Console.ReadLine());
- Console.WriteLine("Enter z:");
- this.z = Int32.Parse(Console.ReadLine());
- }
- public void getVectorPos() {
- Console.WriteLine("Vector Coordinates:" + "x " + this.x + "y " + this.y + "z " + this.z);
- }
- public void sumOfVectors()
- {
- Console.WriteLine("set First Coordinates: ");
- setVectorPos();
- Vector a = new Vector(x, y, z);
- Console.WriteLine("set Second Coordinates: ");
- setVectorPos();
- Vector b = new Vector(x, y, z);
- Vector c = a + b;
- getVectorPos();
- }
- }
- class Program : Vector {
- static void Main()
- {
- Vector vec;
- int point = 0;
- string taker;
- Console.WriteLine("Select to do:");
- Console.WriteLine("set - set vector position");
- Console.WriteLine("get - get vector position:");
- Console.WriteLine("sum - take a sum of 2 vectors");
- while (point == 0)
- {
- taker = Console.ReadLine();
- if ("set".Equals(taker)) { }
- }
- }
- }
- }
Решение задачи: «Как создать объект класса, если в нем реализована перегрузка?»
textual
Листинг программы
- Vector vec = new Vector(0.5, 0.5, 0.5);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д