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);
Can anyone resolve error in this operator overloading problem ??
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Dec 7, 2012, 8:46 AM EST
Manpreet singh3 reputationPosted Dec 7, 2012, 6:41 PM EST