473,404 Members | 2,137 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,404 software developers and data experts.

overload for "operator == "

Hi everybody,

I overloaded "operattor== " for comparing two objects.
However, I can't compare one instance to null valued
object instance.
How to solve this problem?

public class Custom
{
private int m_idx = 0;
public int Idx
{ get.... set ......}
..
..
public static bool operator ==(Custom a, Custom b)
{
//can not use if ( b == null), because endless looping

return a.Idx == b.Idx;
}
..
..
..
}
..
..
..
Custom a = new Custom();
Custom b = null;
if (b == null)
// b = a; to do something
Nov 15 '05 #1
1 1383
Jongmin,
//can not use if ( b == null), because endless looping


if ( (object)b == null )

or

if ( Object.ReferenceEquals( b, null ) )

should work

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2

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

Similar topics

1
by: Matthew Monopole | last post by:
Since in integer we can use either a = -b and a = b - c shouldn't it when we overload operator there'd be two way to overload the minus operator? if so, what's the prototypes? class...
4
by: Chiller | last post by:
Ok, thanks to some good assistance/advice from people in this group I've been able to further develop my Distance class. Since previous posts I've refined my code to accept the unit measurement...
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;
5
by: Robin.Liu | last post by:
Hello all! I create a class A, and I want to insert an integer into the object of class A directly. Like this A a = new A(); a = 1; The compiler doesn't allow me to overload the operaotr...
2
by: vcmkrishnan.techie | last post by:
Hi all, In managed C++, can I overload the operator to access data members in the following way Create object objTime; seconds = obj; or seconds = obj;
6
by: Lighter | last post by:
Big Problem! How to overload operator delete? According to C++ standard, "A deallocation function can have more than one parameter."(see 3.7.3.2); however, I don't know how to use an overloaded...
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{
2
by: Mahain | last post by:
How we overload '=' operator using friend function in c++. if not why ????????????????????
1
by: Maximus | last post by:
I am trying to find a way to overload operator new of a class to use a specialzied memory manager. In my design multiple memory managers exist. I need to pass the instance of a memory manager into...
2
by: Markjan | last post by:
I have a problem with classes and structures in classes (C++) I have to overload operator . class Data { public: class Proxy { //for overload operator Data& _a; int...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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,...
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
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,...
0
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...

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.