[cs13001] comparing ship and location

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Oct 29 12:32:16 EDT 2014


> I was trying to figure out why this function is even necessary.  I'm in the
> Monday class so we're working a week behind.  Is my logic sound?
> 
> Ship public member function match can access it's private object loc.
> Function compare cannot because it is friends with objects of type
> location, but it's not friends with ship.  So it has to be invoked inside
> of a member function of ship.  Match can take ship's private object loc and
> pass it to the compare function as a parameter because match is a member
> function of ship.  I'm trying to understand exactly what I'm doing and why
> at every step.
> 
> bool ship::match(location &coords) const{
>    return compare(loc, coords);
> }

The above function is correct. Here is the need for this function. We
need to compare the ship's location "loc" with another location
"coords". The comparison of the two locations involves comparison of X
and Y coordinates. X and Y are private variables of class "location"
These private variables are unavailable inside match() which is a
member function of class "ship". Hence, the way to compare ship's
location with another location is to invoke compare() as you do above.

Thanks,
--
Mikhail


More information about the cs13001 mailing list