   (C++) Passing a class as a functions argument
  Ok I had a program that used structs for holding a hero characters data, I want to try and duplicate the same program using a c++ class object. I have a class called hero that looks like this:class hero { public:   hero();   ~hero();   void set_name(string n);   void set_class(string c);   void set_health(float h);   void set_attack(int a);   void set_defense(int d);   void set_knowledge(int k);   void set_power(int p);   void get_name();   void get_class();   float get_health();   int get_attack();   int get_defense();   int get_knowledge();   int get_power();   void create_hero(); protected:   string name;   string hclass;   float health;   int attack;   int defense;   int knowledge;   int power;};and i have a function that is supposed to print the values of the hero classes variables. The basics of the function look like this:void print_hero_stats(class hero *player){system("cls");cout << "Name: " << player->get_name() << endl;cout << "Class: " << player->get_class() << endl;cout << "Attack: " << player->get_attack() << endl;cout << "Defense: " << player->get_defense() << endl;cout << "Knowledge: " << player->get_knowledge() << endl;cout << "Power: " << player->get_power() << endl;system("pause");}so i create my instance of my hero class withhero Player;and call my function with print_hero_stats(&Player); what is the correct method for passing all the information of my hero class to my other function.   
hero Player;void print_hero_stats( hero *player ) // use a pointer parameter{// code}// now you call it using the addressprint_hero_stats( &Player );edit: that's exactly what you've done   ;  You don't need to specify the keyword class in your function definitionYou should probably make your variables private unless your going to use inheritance and create derived versions of hero btw, besides you have provided setters and getters for all the stats so they are accessible anyhow.   ;  ^^ This, also remember you aren't passing a class, you're passing an object.   ;  ok so I am passing the hero class ive created properly, so how do I access the functions in the hero class from inside my other function, i know that when i used it in my file using structures once passed i usedplayer->nameto get the name, however this didnt include calling functions, so what is the proper way to call the hero classes get/set functions from inside this print function.i have tried everything I can think of such as player->get_name() and player.get_name()is there a different method required to call them?   ;  Well it depends, if your function declaration takes a reference:Hero myHero;void print(Hero & hero){hero.get_name();  //Returns the name}However if you use a pointer:Hero* myHero = new Hero();void print(Hero * hero){hero->get_name(); //Returns the name}Don't try to fight against the compiler, learn the language first then write the code.In C++ you can pass parameters into functions in two ways:1) By Value2) By ReferenceIf you are dealing with complex objects you should never really pass by value as when the function is called it will create a full copy of the object on the stack.Pass by reference means it passes "a reference" to the object you passed in, hence it basically reuses the object you created in your main function.  If you are not going to modify it you can pass it as a const reference (but make sure your getters are const functions).In the first example above you are passing by reference, in the second you are passing by value but it is not inefficient as you are only passing a pointer.  A pointer is basically a memory address and takes up 4 bytes of memory, even though your object itself is larger, you are just passing the memory address of where it lives, which is why you have to use the dereference (->) in order to access its member, by reference however gives you direct access which is why we can access it using (.)If your not getting any output it could be an issue with how you are getting / setting your string objects, it could be that you are returning a new instance of string (hence its empty) or you are not setting them properly.  Just a case of debbuging and reading up on the std::string (which I presume you are using)   