Access to object members

Here is the scenario,

I have 2 separate classes, 1 called player and 1 called camera.

I need a function in a camera object to have access to a variable that is part of a player object.

I have looked around on the internet and tried to use pointers with no luck.

If you understand what I'm after please let me know if its even pointers that I'm after or is there another way of doing it?

Thanks very much.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class camera;
class player{
private:
   T some_var;
public:
   void foo(camera &pov);
};

class camera{
public:
   void bar(T &some_var);
};


void player::foo(camera &pov){
   pov.bar( this->some_var );
}

int main(){
   camera hawk_eye;
   player p[4];
   //...
   p[0].foo(hawk_eye);
}
¿what kind of access do you need?
Last edited on
I need a function from a camera object to get the player object's x, y, z coordinates.
(which are stored as float variables in player object)

The camera object can then use these coordinates and follow them.
Last edited on
Topic archived. No new replies allowed.