M
MM
Hi,
class A
{
protected int anum;
}
class B : A
{
public static B operator ++(B b_class)
{
b_class.anum++;
return b_class;
}
}
class C : B
{
static void Main(string[] args)
{
C c_class = new C();
c_class.anum = 10;
c_class++; // ERROR - cannot implicitly covert type - are
you missing a cast?
}
Hi, I'm learning. I want to increment a value type buried in a class
hierarchy. I thought that B descendants would inherit default action of ++
defined in Class B but doesn't work. From my reading, it seems that most
operator overloads create a new object and return that but I don't want to
do this. I simply want a value incremented in the base class to be the
standard behaviour in all derived classes. I can sortof understand the
error - the ++ operator returns a class B which can't be recast to a class
C - what do I do? Thanks alot for your help! matt.
class A
{
protected int anum;
}
class B : A
{
public static B operator ++(B b_class)
{
b_class.anum++;
return b_class;
}
}
class C : B
{
static void Main(string[] args)
{
C c_class = new C();
c_class.anum = 10;
c_class++; // ERROR - cannot implicitly covert type - are
you missing a cast?
}
Hi, I'm learning. I want to increment a value type buried in a class
hierarchy. I thought that B descendants would inherit default action of ++
defined in Class B but doesn't work. From my reading, it seems that most
operator overloads create a new object and return that but I don't want to
do this. I simply want a value incremented in the base class to be the
standard behaviour in all derived classes. I can sortof understand the
error - the ++ operator returns a class B which can't be recast to a class
C - what do I do? Thanks alot for your help! matt.