c++ How to use a protected member variable of a class with another class that has aggregation relationship

118 views Asked by At

I'm trying to use aggregation between two classes but my code gives me an error. I used the data type of a class in another class. Basically I tried taking the input of guess(a protected member variable of hangman) in the class of player but it says unidentified. I don't know why thats happening because i have

Player player2;

declared in my hangman headerfile. If someone can help me out I would really appreciate it for I am still learning! Thank you!

In one of my header files I have:

#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();
};

In my player header file i have:

#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;
};

In my player.cpp file i have

#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

}
0

There are 0 answers