Bitwise AND overloading and argument list

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top