[CSI] Lab 9

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Apr 7 00:35:33 EDT 2020


> Hi Mikhail, I'm in CS1B and had a question about Lab 9. Im confused on the
> compare function because I know you can't compare two classes directly but
> I don't remember you saying how you would do it without directly doing it.

You can compare them inside the friend function compare that is
prototyped in class Location. It is not a member function so it should
be invoked as follows

Location x1, x2:

if (compare(x1, x2)) 
   cout << "the two locations are equal!";

The material is on slide 14 of the classes lecture. The use of a
friend function is illustrated in this example:

http://vega.cs.kent.edu/~mikhail/classes/csi/Examples/Classes/friend.cpp


Thanks,
-- 
Mikhail


More information about the cs13001 mailing list