Manpreet singh

Manpreet singh

  • NA
  • 3
  • 2.1k

can anyone resolve error in this operator overloading problem ??

Dec 7 2012 12:57 PM
    class Distance
    {
    int dist;
    public Distance(int d)
    {
        
        this.dist = d;
    }
    public static Distance operator +(Distance d1, Distance d2)
    {
        return new Distance(d1.dist + d2.dist);
    }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Distance d1 = new Distance(3);
            Distance d2 = new Distance(10);
            Distance d3;
            d3 = d1 + d2;
            int a = (int)d3;
            Console.WriteLine(a);

Answers (2)