0
我有一個簡單的應用程序寫在c++
(只是學習),但我的應用程序無法正常運行。這裏是我的代碼:c__app.exe已停止工作?
的main.cpp
#include <iostream>
#include <cstdio>
#include "Player.h"
using namespace std;
int main() {
Player p1("Anish");
Player p2("ASK");
cout << "Game starts." << endl;
cout << p1.getPlayerName() << " has " << p1.getHitPoint() << " hitpoints." << endl;
cout << p2.getPlayerName() << " has " << p2.getHitPoint() << " hitpoints." << endl;
p1.hit(&p2);
// cout << p2.getHitPoint();
cout << p1.getPlayerName() << " hits " << p2.getPlayerName() << endl;
cout << p1.getPlayerName() << " has " << p1.getHitPoint() << " hitpoints." << endl;
cout << p2.getPlayerName() << " has " << p2.getHitPoint() << " hitpoints." << endl;
p1.heal(&p2);
cout << p1.getPlayerName() << " heals " << p2.getPlayerName() << endl;
cout << p1.getPlayerName() << " has " << p1.getHitPoint() << " hitpoints." << endl;
cout << p2.getPlayerName() << " has " << p2.getHitPoint() << " hitpoints." << endl;
return 0;
}
Player.cpp
#include "Player.h"
Player::Player(string name) {
playerName=name;
setHitPoint(100);
}
void Player::setHitPoint(int points){
hitPoint=points;
}
Player Player::hit(Player* p){
Player player=*p;
int point=player.getHitPoint()-10;
player.setHitPoint(point);
}
Player Player::heal(Player* p){
Player player=*p;
player.setHitPoint(player.getHitPoint()+5);
}
Player.h
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#ifndef PLAYER_H
#define PLAYER_H
class Player {
public:
Player(string);
Player hit(Player*);
Player heal(Player*);
void setHitPoint(int);
int getHitPoint() {return hitPoint;};
string getPlayerName() {return playerName;};
private:
string playerName;
int hitPoint;
};
#endif /* PLAYER_H */
帖E碼提供以下的輸出: 構建
Game starts.
Anish has 100 hitpoints.
ASK has 100 hitpoints.
RUN FAILED (exit value -1,073,741,819, total time: 2s)
並停止工作。 任何人都可以提出一個關於這個問題的想法嗎?我也沒有得到任何錯誤。