I was just wondering how ShipPoly knows about BackGround object |
In your Background class, you have declared
friend ShipPoly;
, yes?
This means that
ShipPoly has permission to access the private members of a
Background object.
That is all it means.
It doesn't magically give
ShipPoly a
Background object to modify; your code has to provide that in the same way it would provide
ShipPoly with any other data (e.g. by passing it as an argument to the appropriate method).
It doesn't magically provide to
ShipPoly the definition of the
Background class; your code has to provide that in the the same way as it would provide any other definition (e.g. by
#include-ing the relevant header file).
How to pass the Background object to ShipPoly then? |
That depends entirely on your code design. If there's only one
Background object, then probably best to pass it as an argument to the
ShipPoly constructor, and have
ShipPoly store it as a data member, and modify it each time it updates.
If, on the other hand, there are multiple
Background objects, and you want to choose which one to modify at the time you call
ShipPoly::update(), then you should pass it as an argument to that method.