我一直在尝试将一个包含我所有变量的结构传递给多个函数,这些函数保存在一个单独的类中。我知道这个错误很可能与某种语法错误有关,但我看不出我做错了什么。
main.ccp 是:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include "running.h"
using namespace std;
int main()
{
//------Class Objects---------
running runObj;
//----------Vars--------------
char saveGame = 'N';
struct gameVar
{
int correctGuesses; // These vars need to be reset for each new game.
int Lives;
int rowCorrect;
int highScore;
char anotherGame;
} values;
values.highScore = 12;
values.anotherGame = 'Y';
//--------Game Loop-----------
// int highScore2 = runObj.readHighScore();
while (values.anotherGame = 'Y')
{
struct gameVar = runObj.processGame(gameVar);
struct gameVar = runObj.afterText(gameVar);
gameVar values;
values.anotherGame;
}
cout << endl << "-------------------------------------------------------" << endl;
cout << "Would you like to save your high score? Y/N" << endl;
cin >> saveGame;
if(saveGame == 'Y')
{
runObj.saveHighScore(gameVar);
}
return 0;
}
我的头文件是:
#ifndef RUNNING_H
#define RUNNING_H
class running
{
public:
struct gameVar processGame(struct gameVar);
void saveHighScore(struct hs);
int readHighScore();
struct gameVar afterText(struct gameVar);
};
#endif // RUNNING_H