我正在尝试在两个类之间使用聚合,但我的代码给了我一个错误。 我在另一个类中使用了类的数据类型。基本上我尝试在播放器类中接受guess(一个受保护的hangman成员变量)的输入,但它说不明。我不知道为什么会这样,因为我有
Player player2;
在我的hangman头文件中声明。如果有人可以帮助我,我会非常感激,因为我还在学习!谢谢!
在我的一个头文件中:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Hangman
{
public:
Hangman();
void Play();
protected:
Player player2;
vector<string> words;
int wrong;
const int maxwrong=4;
char guess;
void virtual RespondIncorrectGuess();
};
在我的播放器标题文件中,我有:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Player{
public:
Player();
char MakeGuess();
void Win();
void Lose();
char Agree();
private:
string name;
int score;
};
在我的player.cpp文件中,我有
#include "player.h"
#include "hangman.h"
char Player::MakeGuess()
{
cout<<"Enter your guess"<<endl;
cin>>guess;//i know why this doesnt work but i dont know how to make guess work here
}