operator overloading true and false

R

relient

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.
 
M

Markus Moll

Hi
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
 
R

relient

Oh my god. I cannot believe I just did that, lol - I'm very sorry. I'm
going to delete this thread.
 
R

Richard Heathfield

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.
 
M

Martin Ambuhl

relient said:
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++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,208
Latest member
RandallLay

Latest Threads

Top