【发布时间】:2020-12-07 19:59:15
【问题描述】:
我是 C++ 新手,想知道我做错了什么。
我正在尝试创建一个基于文本的冒险游戏,该游戏使用添加或删除功能来跟踪玩家统计数据。目前,我的函数没有为 trust 添加五个点,我正在努力做到这一点。
#include "function.h"
using namespace std;
int main() {
double trust=100;
editPlayer user(100);
//asks user choice
cin >> firstChoice;
if (firstChoice == 1) {
user.addTrust(trust);
cout << trust;
这是我的function.cpp,仅以信任为例:
#include "function.h"
editPlayer::editPlayer(double trust) {
}
void editPlayer::addTrust(double trust){
trust +=5;
}
void editPlayer::removeTrust(double trust){
trust -=5;
}
这是我的function.h:
#include<iostream>
#include<string>
using namespace std;
class editPlayer{
public:
editPlayer(double trust);
void addTrust(double);
void removeTrust(double);
};
【问题讨论】:
-
你用哪本书来学习C++?这不是类的使用方式。