473,472 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

operator (+) operator

Dear Sir/Madam,
I have 2 lists as following:

ApproverListBE appList1;

ApproverListBE appList2 ;

I want to add the above 2 lists.How do I override the + operator.

Kind Regards,
Nov 17 '05 #1
3 2489
In your ApproverListBE class add

Public static ApproverListBE operator +(ApproverListBE ob1,
ApproverListBE ob2)
{
// Insert code here to add the variables of class ApproverListBE
together

// return instance of ApproverListBE
}
-----Original Message-----
From: enahar [mailto:en****@hotmail.com]
Posted At: Tuesday, 19 April 2005 8:16 AM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: operator (+) operator
Subject: operator (+) operator

Dear Sir/Madam,
I have 2 lists as following:

ApproverListBE appList1;

ApproverListBE appList2 ;

I want to add the above 2 lists.How do I override the + operator.

Kind Regards,
Nov 17 '05 #2
That said, are you really "adding" these two lists? That is, are you
doing a mathematical "+" operation on each item in each list?

Or are you joining the lists together by creating a list that contains
all of the items in both lists?

If I were you I would be very, very leery of overriding the "+"
operator for collections like your lists. In my experience that has
meaning only in vector mathematics.

If you are combining two lists to make a third list that contains
everything in the first two lists (or even folding the contents of a
second list into the first list), then you want to define a static
method like Append(ApproverListBE a, ApproverListBE b), or an instance
method like Append(ApproverListBE otherList) to do the job. Don't use
the "+" operator.

Nov 17 '05 #3
"enahar" <en****@hotmail.com> a écrit dans le message de news:
e1**************@tk2msftngp13.phx.gbl...
I have 2 lists as following:

ApproverListBE appList1;

ApproverListBE appList2 ;

I want to add the above 2 lists.How do I override the + operator.


As Bruce has said, adding lists is not a simple concept. There are three
different set operations available:

Union
The result set contains all the items from both operand sets

Intersection
The result set contains those items that are common to both operand sets

Difference
The result set contains the inverse of an Intersection; those items that are
only found in one or other of the operand sets.

You should also consider whether you want the 'addition' to append one list
to another or to merge the two lists in some implicit order.

For the sanity of those who might have to maintain your code in later years,
I would suggest you do not use operator overloading, but instead use Append
and Merge instance methods; and possibly Union, Intersection and Difference
static methods that take two lists as arguments and return a resulting list.

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #4

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

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
1
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
3
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD...
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
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...
8
by: valerij | last post by:
Yes, hi How to write "operator +" and "operator =" functions in a class with a defined constructor? The following code demonstrates that I don't really understand how to do it... I think it has...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.