I want to update the stats of each actor in my program. But I will need to do it with a single generic function for all stats. At least I prefer to do it with one generic function. Failing that, I want to do it with a function for each stat. I wanted to do something like this:
Whereas anyactor will be the part I am having trouble figuring out. Is there a way to make it so that I can plug any actor (example joe, sally, jimmy) into the function? Maybe replacing anyactor with a reference or pointer of some type? I am looing to do it something like this:
//character is damaged for 5 points
changehitpoints(joe, 5, false);
void setname(string x);
void setlevel(int x);
void setstrength(int x);
void setdexterity(int x);
void setintelligence(int x);
void setcharisma(int x);
void setconstitution(int x);
void setMAX_hitpoints(int x);
void setCURRENT_hitpoints(int x);
void setarmor(int x);
#endif // ACTOR_H
actor.cpp just has simple getter and setter functions so far.
For organisational purposes I want to keep that function separate. Besides, this is for education. Although it may seem like I am trying to make a game, i am only using this to learn new things in c++. The question, is essentially, how do I pass an object as an argument into a function separate from the objects class?
ne555, I don't understand why you think it is obfuscated. Which part/s are you referring to? I have all variables in the class set up with setter and getter functions. The variables are private and the getters and setters are public. I thought was good programming practice. I am only starting to understand things like pointers and classes. I am still a beginner.
Thank you, ne555. This function was still in the experimental(Alpha) phase. It has since been bumped to the Beta phase of development. I wasn't sure what I was going to exactly do with it. Now I think I will be moving it to the actor class since it seems to be a perfect fit. Doesn't the GCC compiler make definitions of member functions inline already?
Doesn't the GCC compiler make definitions of member functions inline already?
Member functions defined inside a class declaration are implicitly inline. However, create_actor is not a member function. If you define a member function outside of the class declaration, it's not inline either.
Tanks for all of your help, everyone. ne555, I was just trying a different way to adjust hitpoints. But i like the joe.changehitpoints(-5); idea. I think i will stick with that. And add an action class to put any stat changing functions into. Thanks again.
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: