Ok here is the sample example:
Code:
public class Base
{
private int a;
public Base(int a)
{
this.a = a;
}
public static Base operator ++(Base B)
{
return new Base(B.a + 1);
}
}
class Derive : Base
{
private int d;
public Derive(int d, int a)
: base(a)
{
this.d = d;
}
}
now in Main, I was trying this:
Code:
Derive d = new Derive(1, 2);
Base b = ++d; // here the error occurs.
I thought on it and found that it is not possible. As compiler understand that it has to call the base class overloaded operator but the parameter is actually a derived one even it inherits the Base class.
There is a naive approach to achieve it as:
Code:
Derive d = new Derive(1, 2);
Base a = d;
Base b = ++a; // no error now.
Since you asked to give a sample example of it, so this is it..
Thanks..