473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloading of the unary ++ operator in VB.net

Overloading of the unary ++ operator in vb.net is not working. It show error:
Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change developing
language to C#? Any suggestion?
Jun 27 '08
15 2021
On 2008-04-29, VB Developer <VB*********@di scussions.micro soft.comwrote:
+= is not work too.

Code:
Public Shared Operator +=(ByVal bi As Integer) As Integer
............... ....

End Operator

Give the same error above.

Please check it before post yours.

Actually, looking in the docs, +=, -=, etc are not valid for
overloading, so the error message is perfectly correct. You would have
to overload the +:

Public Shared Operator +(ByVal bi As Integer) As Integer
End Sub

+= and friends are compiler shortcuts - not actual operators.
--
Tom Shelton
Jun 27 '08 #11
"VB Developer" <VB*********@di scussions.micro soft.comschrieb
+= is not work too.

Code:
Public Shared Operator +=(ByVal bi As Integer) As Integer
............... ....

End Operator

Give the same error above.

Please check it before post yours.
See Patrice' reply. The "real" operator is "+". You will be able to use
"dest += value" just like "dest = dest + value"
Armin

Jun 27 '08 #12

I want to transfer C# code to VB.net code. I know now it is impossible at
some part and except you change original code such as ++ to +1.

"Patrice" wrote:
"Andrew Morton" <ak*@in-press.co.uk.inv alida écrit dans le message de
groupe de discussion : 67************* @mid.individual .net...
Tom Shelton wrote:
On 2008-04-29, VB Developer <VB*********@di scussions.micro soft.com>
wrote:
Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.
Or one of +=, *=, &= and so on, which the help/error message seems to
miss out.

Andrew

Similarly I would say that += etc... doesn't really exists. This is just a
shortcut notation... What if you try just + or whatever fit your needs ?

You may want to explain what you are trying to do...
--
Patrice

Jun 27 '08 #13
"VB Developer" <VB*********@di scussions.micro soft.comschrieb :
Overloading of the unary ++ operator in vb.net is not working. It show
error:
Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

Is there any way can to get rid of this error?
Overload the '+' operator. You may want to handle the case of
incrementation "by one" differently.
C# is working fine for overloading ++, and do I need to change developing
language to C#? Any suggestion?
Why would you want to overload this operator? Note that this operator is
syntactic sugar, as is '+='. VB does not even support the '++' shorthand
syntax.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #14
"Tom Shelton" <to*********@YO UKNOWTHEDRILLco mcast.netschrie b:
>I want to transfer C# code to VB.net code. I know now it is impossible
at
some part and except you change original code such as ++ to +1.

Yep. VB.NET doesn't support pre/post increment/decrement operators.
The closest you get is:

b += 1

or

b -= 1

And that is just a shortcut for:

b = b + 1

or

b = b -1

One more reson to prefer C# :)
Well, opinions seem to differ. I don't see any reason for an additional way
to achieve a certain thing which only saves a few keystrokes but requires
additional keystrokes if incrementation/decrementation should be changed
from 1 to another value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #15
On 2008-05-01, Herfried K. Wagner [MVP] <hi************ ***@gmx.atwrote :
"Tom Shelton" <to*********@YO UKNOWTHEDRILLco mcast.netschrie b:
>>I want to transfer C# code to VB.net code. I know now it is impossible
at
some part and except you change original code such as ++ to +1.

Yep. VB.NET doesn't support pre/post increment/decrement operators.
The closest you get is:

b += 1

or

b -= 1

And that is just a shortcut for:

b = b + 1

or

b = b -1

One more reson to prefer C# :)

Well, opinions seem to differ. I don't see any reason for an additional way
to achieve a certain thing which only saves a few keystrokes but requires
additional keystrokes if incrementation/decrementation should be changed
from 1 to another value.
it's the pre/post thing that comes in handy sometimes... Not
necessarily the shortcut for += 1.

--
Tom Shelton
Jun 27 '08 #16

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

Similar topics

4
1780
by: PKH | last post by:
This is a part of an autopointer template i'm using. I originally had a Get() member that returned the pointer, but thought it would nice to be able to use the -> operator. The question is why does the following line work, and call cAP.m_pcPointer->Testing() ? cAP->Testing(); // ??? cAP-> returns a CTest*, so it looks to me like the line reads cAP.m_pcPointer <whitespace> Testing(), but it actually does
2
1361
by: Ook | last post by:
This is a few ways I've seen to overload operator+. I can understand that you would want to pass a reference to the function if you wanted to change some of the data elements of the class, but in the first example it's being passed as a constant. Is this done for performance purposes so that it doesn't create a copy of the class and pass the copy to the function? Why would you have it return a reference to the class as in example 1? I...
0
1148
by: Leszek Taratuta | last post by:
Hello, I have the following code snippet that overloads the "-" operator: // unary public static Vector operator -( Vector v ) { return new Vector( -v.X, -v.Y ); }
5
3634
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), , ->, =. I wonder why there is such a restriction. Some tutorials say that 'new' and 'delete' can only be overloaded with static member functions, others say that all overloading function should be non-static. Then what is the fact, and why? ...
6
2590
by: Matthew Cook | last post by:
I would like to overload the unary minus operator so that I can negate an instance of a class and pass that instance to a function without creating an explicit temporary variable. Here is an example: #include <iostream> using namespace std; class Object { public:
19
2304
by: Jess | last post by:
Hello, After seeing some examples about operator overloading, I'm still a bit confused about the general syntax. The following is what I think, not sure whether it's correct. 1. For a unary operator that's a member of a class, its form is usually "operatorP()" (where P is the operator's name).
8
2979
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular, operator =, operator, operator(), and operator-must be nonstatic member function; this ensures that their first operands will be lvalues". I know that these operators must be nonstatic member functions, but why this ensure their first operands will...
2
2953
by: jimzat | last post by:
I am trying to simulate the execution of some PLC ladder logic in python. I manually modified the rungs and executed this within python as a proof of concept, but I'd like to be able to skip the modification step. My thought was that this might be able to be completed via overloading, but I am not sure if (or how) it could be done. overloadings: + ==OR
1
4460
by: haderika | last post by:
Hey, I'm having trouble overloading the ~ operator (the determinant of the matrix) in a case of 2x2 matrices. So i have a matrix class, with the constructor, overloading +, += and ~ operators. the first two are working but I don't know how to overload the ~ one. here's what I have: matrix matrix::operator~(matrix &m) { double x; x=(m.a11*m.a22)-(m.a12*m.a21); return x; of course it's not working cause i can't return a double value...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.