Click to See Complete Forum and Search --> : Help with this question
//Suppose that the class declaration of SomeClass
//includes the following function prototype
Boolean LessThan (/*in*/ SomeClass another Object);
//Which of the following tests in the client code
//correctly compares two class objects alpha and beta?
//a. if(alpha < beta)
//b. if(alpha.LessThan(beta))
//c. if(LessThan(alpha, beta))
//d. if(alpha.LessThan.beta)
//e. if(LessThan(alpha).beta)
"Eric" <etimesthree@t-online.de> wrote:
>
>//Suppose that the class declaration of SomeClass
>//includes the following function prototype
>
> Boolean LessThan (/*in*/ SomeClass another Object);
>
>//Which of the following tests in the client code
>//correctly compares two class objects alpha and beta?
>
>//a. if(alpha < beta)
>//b. if(alpha.LessThan(beta))
>//c. if(LessThan(alpha, beta))
>//d. if(alpha.LessThan.beta)
>//e. if(LessThan(alpha).beta)
I believe the answer is b.
Khaled
07-23-2002, 09:29 AM
well, either :
alpha.LessThan(beta);
or :
beta.LessThan(alpha);
depending on which want u want to cjeck if 'less than' the other ,
also I don't think I ever saw a 'Boolean' in C++, so I guess it should be
bool unless Boolean is a user defined type or if it is there and I don't
know, or maybe a certain compiler implements it as a non standard, I'am not
sure.
if u want to use the < operator then u'll have to overload it
bool operator<(SomeClass another_type); // I guess again :-)
"Eric" <etimesthree@t-online.de> wrote:
>
>//Suppose that the class declaration of SomeClass
>//includes the following function prototype
>
> Boolean LessThan (/*in*/ SomeClass another Object);
>
>//Which of the following tests in the client code
>//correctly compares two class objects alpha and beta?
>
>//a. if(alpha < beta)
>//b. if(alpha.LessThan(beta))
>//c. if(LessThan(alpha, beta))
>//d. if(alpha.LessThan.beta)
>//e. if(LessThan(alpha).beta)
James Curran
07-23-2002, 10:07 AM
"Khaled" <khm@link.net> wrote in message news:3d3d5a20$1@10.1.10.29...
>
> bool operator<(SomeClass another_type); // I guess again :-)
>
That's a bit vague as to how you are defining it. I assume you want:
> bool SomeClass::operator<(SomeClass another_type);
That is, as a member function of SomeClass. The problem is that's not the
best way. Better is to declare it as a global function:
bool operator<(const SomeClass& lhs, const SomeClass& rhs)
{.....}
--
Truth,
James Curran
www.NovelTheory.com (Personal)
www.NJTheater.com (Professional)
www.aurora-inc.com (Day job)
devx.com
Copyright Internet.com Inc. All Rights Reserved