T
t f
hi
just a quick question - i have the something like the following
public abstract class ClassA
{
protected int iA;
public int Value { get {return iA;} set { iA = value;}}
public ClassA(int value)
{ iA = value; }
public static ClassA operator +(ClassA a1, ClassA a2)
{
a1.Value = a1.Value + a2.Value;
return a1;
}
public static ClassA operator -(ClassA a1, ClassA a2)
{
a1.Value = a1.Value - a2.Value;
return a1;
}
}
public class ClassB : ClassA
{
public ClassB(int value) : base(value)
{ }
}
public class ClassC : ClassA
{
public ClassB(int value) : base(value)
{ }
}
Problem is, if i try this
ClassB cb1 = new ClassB(1);
ClassB cb2 = new ClassB(2);
ClassB cb3 = cb1 + cb2;
I get an error as cb1 + cb2 is of type ClassA....
Question: Is there a way of putting all my operator overloads in the base
class and instead of having to put them in each of the derived classes?
Thanks
t f
just a quick question - i have the something like the following
public abstract class ClassA
{
protected int iA;
public int Value { get {return iA;} set { iA = value;}}
public ClassA(int value)
{ iA = value; }
public static ClassA operator +(ClassA a1, ClassA a2)
{
a1.Value = a1.Value + a2.Value;
return a1;
}
public static ClassA operator -(ClassA a1, ClassA a2)
{
a1.Value = a1.Value - a2.Value;
return a1;
}
}
public class ClassB : ClassA
{
public ClassB(int value) : base(value)
{ }
}
public class ClassC : ClassA
{
public ClassB(int value) : base(value)
{ }
}
Problem is, if i try this
ClassB cb1 = new ClassB(1);
ClassB cb2 = new ClassB(2);
ClassB cb3 = cb1 + cb2;
I get an error as cb1 + cb2 is of type ClassA....
Question: Is there a way of putting all my operator overloads in the base
class and instead of having to put them in each of the derived classes?
Thanks
t f