Classes, Pointers, and Functions

Ok, lets say I have a generic function like this:

1
2
3
void send_name(animate* Animate) {
   cout<<Animate->getname();
}


And I have classes like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class animate {
   string name;
public:
   string getname() const;
   void setname(string new_name);
}

class mobile: public animate {
   bool attackable;
public:
   void setattackable(bool new_state);
   bool getattackable() const;
}

class player: public animate {
   bool afk;
public:
   void setafk(bool new_state);
   bool getafk() const;
}


Now the annoyance is I am passing a reference to a player object to a function like this:

1
2
3
void cheer(player &Player) {
   cout<<send_name((animate*)&Player)<<" cheers!";
}


Normally, this wouldn't be annoying, but I have a very large amount of functions that are calling this function, and they take multiple arguments.

So, I am asking, is there an easier way to do this? Could I just pass pointers to all of the functions instead of references so I wouldn't have to go do all this casting?
Wouldn't any class drived from animate, have a access to the getname function - so you wouldn't need to cast.
Yes, but this is just an example of how the problem comes up, it's that I have a function that references a bunch of other variables inside of animate to do its work (to decide whether to send the data to them or not, etc)
Topic archived. No new replies allowed.