[cs23021] Lab 9 Problem
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Oct 26 21:52:58 EDT 2010
> I am still having problems with lab 9. My main problem seems to be
> referring to variables from other classes and calling functions from
> other classes.
You cannot access the object's private variables outside its member
functions. This violates encapsulation. In the below function you are
trying to access the private variables of "loc" - an object of class
"location" inside the function "match" which is not the member
function of class location.
You should use "compare" inside ship::match() to compare two
locations.
Thanks,
--
Mikhail
> --------This code returns error "within this context" on line 3----------
>
>
> bool ship::match(location guess) const {// returns true if this
> location matches // the ship's location
> bool matches = false;
> if ((guess.x == loc.x) && (guess.y == loc.y))
> matches = true;
> return matches;
> };
More information about the cs23021-2
mailing list