Passing C++ objects by reference for participants in a simulated battle I just started watching C++ videos couple of days ago. I tried taking everything I learned about classes and passing by references vs values. The main question I what would like to know is this the correct way to change the values of private class members or is there a more 'professional' way of doing it. (Or standard).

Entity.cpp: 

void Entity::playerAttack(Entity &amp;Player, Entity &amp;Enemy) {
    cout &lt;&lt; "\nPlayer is Attacking!" &lt;&lt; endl;
    cout &lt;&lt; "Enemy's health was at: " &lt;&lt; Enemy.getHealth() &lt;&lt; endl;
    totalHealth = Enemy.getHealth() - Player.getDamage();
    Enemy.setHealth(totalHealth);

    if (Enemy.getHealth() &lt;= 0) {
        Enemy.setHealth(0);
        cout &lt;&lt; "\nEnemies is 0 or below" &lt;&lt; endl;
        cout &lt;&lt; "Players health is at: " &lt;&lt; Player.getHealth() &lt;&lt; endl;
    }
    else {
        cout &lt;&lt; "Enemies health is now at: " &lt;&lt; Enemy.getHealth() &lt;&lt; endl;
    }
}

void Entity::setHealth(float x) {
    health = x;
}

void Entity::setDamage(float x) {
    damage = x;
}

float Entity::getDamage() {
    return (damage);
}

float Entity::getHealth() {
    return (health);
}


Entity.h: 

#pragma once
class Entity
{
public:
    void setHealth(float x);
    void setDamage(float x);
    void playerAttack(Entity &amp;Player, Entity &amp;Enemy);
    float getHealth();
    float getDamage();

    Entity();
    ~Entity();

private:
    float health;
    float damage;
    float healAbility;
    float totalHealth;
};


source.cpp:

Entity constructE(float damage, float health, float regen) {
    Entity Entity;
    Entity.setDamage(damage);
    Entity.setHealth(health);
    Entity.setRegen(regen);

    return (Entity);
}

int main() {
    Entity Player = constructE(10, 100, 10);
    Entity Monster = constructE(5, 20, 5);
    Player.playerAttack(Player, Monster);
}
I have a couple of issues with how you are doing this (it is very Java like not C++ like).

Constructors

After the constructor finishes your object should be in a valid consistent state. Having to call multiple "setters" to finish initialization is a big red flag.

Entity constructE(float damage, float health, float regen) {
    Entity Entity;
    Entity.setDamage(damage);
    Entity.setHealth(health);
    Entity.setRegen(regen);

    return (Entity);
}


Why not just have a "constructor" that takes these arguments.

Entity Player = constructE(10, 100, 10);

// Should look like:
Entity Player(10, 100, 10);


Passing an object to itself?

Player.playerAttack(Player, Monster);


You are passing player as an argument? As you are calling a method on the object "player" you already have access to the player (via this). So there is no need to pass the player here.

player.attack(monster);


Identifier conventions.

One thing I notice about your code is that everything starts with a capitol letter. This makes it hard to tell the difference between types and objects. One of the most important things in C++ is type.

So the usual convention is that "User Defined Types" have an initial capitol letter. While objects (variables) have an initial lower case letter.

player.attack(monster);
^ Object      ^ Object


While:

Player.attack(monster);
|             ^ object
^ Looks like a type.
  So attack looks likes a static member function (ie a class method).


Getters/Setters

Getters and Setters break encapsulation. They expose the internal implementation details of the class. If you see the pattern

 auto x = object.getValue();
 auto y = performSomeAction(x);
 object.setValue(y);


Then this is usually an indication that you have not designed your class well as you expose internal details to calculate a value. A better design would be to provide a method that performs an ACTION on the class.

 object.someAction();   // internally it can update its own state.


Re-Design

class Entity
{
public:
     Entity(int damage, int helath, int regen)
         : damage(damage)
         , health(health)
         , healAbility(regen)
    {}
    // Destructor not needed.

    // Check if an entity is alive.
    operator bool() const
    {
        return health &gt; 0;
    }
private:
    // Internal use only by attack()
    int weaponDamage() const
    {
        return myRandomNumber() % 10;  // Damage in the range 0..9
    }

    // Take damage
    Entity&amp; takeDamage(int amount)
    {
        // Can not go below zero.
        health = max(0, health - amount);
        return *this;
    }
public:

    // Attack an Enemy
    void attack(Entity &amp;enemy)
    {
        std::cout &lt;&lt; "Player:     " &lt;&lt; *this
                  &lt;&lt; "Attacking:  " &lt;&lt; enemy;

        // Damage the enemy and check if he is alive in one line.
        if (enemy.takeDamage(weaponDamage()) {
            // Enemy Alive
            cout &lt;&lt; "E. Status: " &lt;&lt; enemy;
        }
        else {
            // Enemy Dead
            cout &lt;&lt; "Enemies is Dead" &lt;&lt; "\n";
            cout &lt;&lt; "P: Status: " &lt;&lt; *this;
        }
    }

    virtual std::ostream&amp; print(std::ostream&amp; str) const
    {
        return str &lt;&lt; "health: "       &lt;&lt; health 
                   &lt;&lt; " damage: "      &lt;&lt; damage
                   &lt;&lt; " healAbility: " &lt;&lt; healAbility
                   &lt;&lt; "\n";
    }
    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; str, Entity const&amp; data)
    {
        return data.print(str);
    }
private:

private:
    float health;
    float damage;
    float healAbility;
};