473,378 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

operator ~ claimed to be binary by compiler!

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 - no****@nowhere.com :-)

Nov 17 '05 #1
1 848
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).

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jonny Iversen | last post by:
My VC++ documentation state that this is the one complements operator ~0 = 0xFFFF aka all bits set (swapping all 0's to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000...
5
by: Teddy | last post by:
Hello all consider the class Date declaretion below: class Date { public: Date(); Date(int year, int month, int day); Date(const string&); int getYear() const;
14
by: Tony Johansson | last post by:
Hello Experts! Assume I have a class called SphereClass as the base class and a class called BallClass that is derived from the SphereClass. The copy constructor initialize the left hand object...
17
by: Anoob | last post by:
Can we consider () unary operator when calling a function, in exps eq. f(), ( 1 + 2). But when we call function f( 10 ) it is a binary operator. Even if we pass f( 10, 20) as we are using ,...
2
by: linq936 | last post by:
Hi, I have this piece code, struct TriStr { MyString str1; MyString str2; MyString str3; TriStr(MyString s1, MyString s2, MyString s3){ this->str1 = s1;
3
by: karthik | last post by:
The * operator behaves in 2 different ways. It is used as the value at address operator as well as the multiplication operator. Does this mean * is overloaded in c?
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
14
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.