473,413 Members | 1,727 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,413 software developers and data experts.

operator overloading true and false

Hi, there. I need two simple things explained to me:

1.) I want to know why the "true" overloaded operator method gets
called with a test to a null-initialized instance:

public class AnimalClass
{
public static bool operator true( AnimalClass lhs )
{
Console.WriteLine("In true operator");
return true;
}

public static bool operator false( AnimalClass lhs )
{
Console.WriteLine("In false operator");
return false;
}
}

public class MainClass
{
public static void Main( )
{
AnimalClass A = null;

if ( A )
Console.WriteLine("true");
}
}

// output: In true operator
// is true

2.) How can you call the "false" operator method? because I've tried to
in many ways and I cannot get it to be invoked - only "true" works.

Thanks,
relient.

Jan 15 '06 #1
5 1777
Hi

relient wrote:
Hi, there. I need two simple things explained to me:

[some code]

Your code looks like Java or C#, certainly not like C.
Please ask in a newsgroup that deals with the language you have problems
with (like comp.lang.java.programmer or
microsoft.public.dotnet.languages.csharp)

Oh, I just see that you have already posted to mpdl.csharp. Leaves me
puzzled...

Markus

Jan 15 '06 #2
Oh my god. I cannot believe I just did that, lol - I'm very sorry. I'm
going to delete this thread.

Jan 15 '06 #3
relient said:
Oh my god. I cannot believe I just did that, lol - I'm very sorry. I'm
going to delete this thread.


Good luck with that. Servers around the world are carrying the thread, and
they ain't necessarily going to let you blow it away.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jan 15 '06 #4

Jan 15 '06 #5
relient wrote:
Hi, there. I need two simple things explained to me:
You need *one* simple thing explained to you:
1.) I want to know why the "true" overloaded operator method gets
called with a test to a null-initialized instance:

public class AnimalClass


C is not C++. For questions about the programming language C++, ask in
news:comp.lang.c++.
Jan 16 '06 #6

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

Similar topics

3
by: Rama | last post by:
wht is operator overloading, how you overload an operator
2
by: ryan.fairchild | last post by:
I have a problem I am trying to create a MyInt class to hanlde very large ints. Its for a class, therefore I can only do what the teach tells me. I want to be able to overload the insertion...
2
by: emma middlebrook | last post by:
Hi Having difficulty getting myself clear on how a type's operator== fits in with Object.Equals. Let's just consider reference types. The default operator== tests for object identity...
4
by: Peter | last post by:
The Operator overloading in C# has one limitation which I have not seen stated explicitly anywhere. Take the following example public class A { int m_A; public A(int a) {
10
by: Wilhelm Heramb | last post by:
What is the best practice to implement operator overloading for == and != that handles null on either lhs or rhs. Andreas :-)
32
by: John Davis | last post by:
One interesting observation I found is VB6 or VB.NET overloads = opeartor. i.e. = operator has 2 meanings. Case 1: relational operator. In other languages, usually use == instead. If a = b Then...
2
by: xllx.relient.xllx | last post by:
Hi, there. I need two simple things explained to me: 1.) I want to know why the "true" overloaded operator method gets called with a test to a null-initialized instance: public class...
2
by: Tom Smith | last post by:
I'm having difficulty with overloading ==, and it's making my brain melt - can you help...? What I want to have is: 1) A base class A with virtual operator== defined (no problem) 2) A class B...
2
by: Constantine | last post by:
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and...
3
by: Constantine | last post by:
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
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...
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...
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...

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.