Im writing a camera manager(singleton class) and a camera class
there is just one camera (I call it real camera)
my cameraManager holds a list of cameraPrototips,
these camera Prototips arent real cameras, they just hold
position, oriantation, and frustum properties,
when I activate a camera via camera manager, cameraPrototip take the
real camera and set it's informations
My question is that,
There is a member(real camera) which two diffrent classes share(cameraManager and cameraPrototip) I need a way to reach that camera, I put the real cameras pointer to the camera manager class. When ever I push a new cameraPrototip to the list I pass the real camera's pointer with it,
is there a way to make that realcamera visible to other classes ?
such as making it friend member (like friend function)
realCamera is a huge object, because it is huge I dont make copies of it
instead, I make a smaller camera wich control the realcamera, and there must be a way as soon as a prototip camera is created it should know the realcamera's adress to controll it.
I have two solution
1- passing the realcamera's pointer adress to prototipcamera's constructor
(this is complately waste full because there is one camera)
2- making realcamera a global object
however I wonder if there is a way to create a prototip wich know realcamera's adress initially
actually Im using first solution but I encounter this kind of problems alot, and I want to know if there is a way to tell a class that it should know a specific objects adress initially
As I understand it quickly from placeholder and handling the real functionaly by derived, what I would suggest is to write a base abstract class which is not a real camera (as an abstract can not instantiated) but with placeholder for all the functions that to be handled/overridden by its derived (ie, real) cameras.
Since a base class pointer recognizes its derived type objects, write your manager function or whatever, that handles all real cameras (via a base-class type pointer) and then inside the function you take care of it what would be done depending on the passed-in camera type really pointing-to (possibly by using dynamic_cast<>).
I guess an "is-a" (inheritance) relation is more/better applicable than a "has-a" (composite or aggregation) relation for this one. As I suggested abstract and overriding by derived, I had "is-a" relation in my mind as suggestion.