operator ~ claimed to be binary by compiler!

P

Peter Bromley

Hi,

I have a managed __value type which I am attempting to create and use
but there are a number of problems - seemingly in the C++ compiler.

From MSDN: operator ~() should be equivalent to op_OnesComplement and I
believe the signature is:

static MyType op_OnesComplement(MyType left)

But when I attempt to use the operator with

x = ~y;

I get "error C2678: binary '~' : no operator found which takes a
left-hand operand of type 'MyType' (or there is no acceptable conversion)"

Additionally the compiler doesn't seem to understand the following
statements either:

x &= y; // op_BitwiseAndAssigment?
x != y; // op_BitwiseOrAssigment?
x ^= y; // op_ExclusiveOrAssignment?

Is there anybody who knows if either of these is a compiler problem or
am I just plain doing something wrong?

Thanks,
Peter Bromley
--
If you wish to reply to me directly, my addres is spam proofed as:

pbromley at adi dot co dot nz

Or if you prefer - (e-mail address removed) :)
 
T

Tomas Restrepo \(MVP\)

Hi Peter,
I have a managed __value type which I am attempting to create and use
but there are a number of problems - seemingly in the C++ compiler.

From MSDN: operator ~() should be equivalent to op_OnesComplement and I
believe the signature is:

static MyType op_OnesComplement(MyType left)

But when I attempt to use the operator with

x = ~y;

I get "error C2678: binary '~' : no operator found which takes a
left-hand operand of type 'MyType' (or there is no acceptable conversion)"

I believe this is a bug in the compiler. It is failing to mark the
op_OnesComplement method with "specialname", and thus it won't be recognized
as an overloaded operator. While we're at it, there's some precedent here,
as the same happens for op_True and op_False.
Additionally the compiler doesn't seem to understand the following
statements either:

x &= y; // op_BitwiseAndAssigment?
x != y; // op_BitwiseOrAssigment?
x ^= y; // op_ExclusiveOrAssignment?

Huh.... those don't even exists ;). In .NET, there is no op+assignment
overloads, since they are "generated" as op & assignment (meaning, in C#,
the compiler synthetises those variants from the overloaded operator).
 

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

Top