I searched a bit but couldn't find anything specific.
Let's say i have something like this:
Class RedBattleship
{
public:
void TakeDamage();
private:
int m_healthPoints;
};
RedBattleship::RedBattleship(int healthPoints) m_healthpoints(healthPoints)
{
cout << "New red battleship has been constructed";
}
void TakeDamage()
{
m_shields -= 100;
}
//new class
Class BlueBattleship
{
public:
void TakeDamage();
private:
int m_healthPoints;
};
BlueBattleship::blueBattleship(int healthPoints) m_healthpoints(healthPoints)
{
cout << "New blue battleship has been constructed";
}
void TakeDamage()
{
m_shields -= 100;
}
int main()
{
RedBattleShip RedBattleShip1; // initializes object named RedBattelShip1 of the RedBattleShip class
BlueBattleShip BlueBattleShip1; // initializes object named BlueBattleShip1 of the BlueBattleShip class
//now i would like to know if there is i way to simply call the function TakeDamage() from one to hurt the another .. something like this:
RedBattleShip1.TakeDamage(); /* i tried to define this function "TakeDamage()"(class RedBattleShip) earlier in the definition scopes like this
void TakeDamage(BlueBattleShip::int& m_HealthPoints)
{
m_healthPoints -= 100; --- so here i tried to simply call the red battleship function and access the blue battleship member in order to simulate taking damage to the blue ship trough the red one. */
// this is all just in my head, again sorry if this seems stupid i am just inpatient atm :) soz..
Any help would mean much, thank you!
}
return 0;
}


Sign In
Create Account


Back to top









