Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Bitwise AND overloading and argument list

Reply
Thread Tools

Bitwise AND overloading and argument list

 
 
mweltin@gmail.com
Guest
Posts: n/a
 
      05-14-2007
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

 
Reply With Quote
 
 
 
 
mweltin@gmail.com
Guest
Posts: n/a
 
      05-15-2007
I think I found my answer after all.
http://groups.google.com/group/comp....53840ea9aa0cdf
suggests to declair the non member overloaded function as a "friend"
within the A class.

thank you,
Markus

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..." Jim Cochrane Perl Misc 4 10-03-2007 02:35 AM
why doesn't this argument list need a comma after the 1st argument? Dave Slayton Perl Misc 1 03-11-2007 03:25 AM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM



Advertisments