1
I have the following code:
#include <iostream>
using namespace std;
class guns{
public:
string name;
int ammo;
void reload(){
ammo = pente;
}
void shoot(){
ammo -= 1;
}
private:
int pente = ammo;
};
int main(){
guns fuzil;
fuzil.name = "M-16";
fuzil.ammo = 50;
cout << "O fuzil " << fuzil.name << " tem " << fuzil.ammo << endl;
fuzil.shoot();
fuzil.shoot();
cout << "ammo: " << fuzil.ammo << endl;
fuzil.reload();
cout << "carregado: " << fuzil.ammo;
}
The exit is:
O fuzil m16 tem 50
ammo: 48
carregado: 31
Because when Reload() is executed 'Ammo' has the bizarre value 31?