M
mweltin
Dear list memebers:
I have been searching google and various lists but have come up with
little that helps me. Perhaps it is my lack of diction that limits my
search results. Be that as it may, I'm almost sure this question has
been answered but I'll ask anyway in hopes that someone would point me
in the right direction.
My task is to overload the binary bitwise & operator. My class A, has
as one of its members a long unsigned int, and when the this class is
AND'ed with another long unsigned int I would like it to AND with the
classes memeber. In fact I have this working
Class A {
public
int b;
long unsigned int c:
long unsigned int operator&(unsigned long int right ){
long unsigned int retval;
retval = this->c & right;
return retval;
}
......
};
In my test program a call such as this works well
A blah;
x = long unsgined int.
r = blah & x;
but a call such as this fails to compile
r = x & blah;
I have made a non member function
long unsigned int operator&(unsigned long int left, const A right )
long unsigned int retval;
retval = left & right.c ;
return retval;
}
which comiplies into some object code (I complie my classes seperately
as objects and then link them into
my test program).
I'm kind of at a loss for how to overload the AND binary operator in
such a way that it is transparnent for the programer that uses my
class. I would not like to have to put the left and right operands in
a specific order, that is just not intuitive.
thank you,
Markus Weltin
I have been searching google and various lists but have come up with
little that helps me. Perhaps it is my lack of diction that limits my
search results. Be that as it may, I'm almost sure this question has
been answered but I'll ask anyway in hopes that someone would point me
in the right direction.
My task is to overload the binary bitwise & operator. My class A, has
as one of its members a long unsigned int, and when the this class is
AND'ed with another long unsigned int I would like it to AND with the
classes memeber. In fact I have this working
Class A {
public
int b;
long unsigned int c:
long unsigned int operator&(unsigned long int right ){
long unsigned int retval;
retval = this->c & right;
return retval;
}
......
};
In my test program a call such as this works well
A blah;
x = long unsgined int.
r = blah & x;
but a call such as this fails to compile
r = x & blah;
I have made a non member function
long unsigned int operator&(unsigned long int left, const A right )
long unsigned int retval;
retval = left & right.c ;
return retval;
}
which comiplies into some object code (I complie my classes seperately
as objects and then link them into
my test program).
I'm kind of at a loss for how to overload the AND binary operator in
such a way that it is transparnent for the programer that uses my
class. I would not like to have to put the left and right operands in
a specific order, that is just not intuitive.
thank you,
Markus Weltin