I have only been working with C++ for a year now and I am hoping to gain a better understanding of abstraction with my current project. I created a Black Jack card game from my book 'Beginning C++ Through Game Programming'. The game works, but I am working on a menu option that restarts the game, adds scores and allows you to view the scores via fstream.
This is what the menu section looks like inheriting from the base class Game:
class Menu
{
public:
Menu();
~Menu();
private:
Game m_game;
//saves scores to fstream from class Player m_player;
//menu options
void choice();
};
Menu::Menu() {} //no appropriate default constructor available for Game
Menu::~Menu() {}
void Menu::choice()
{
char respond;
bool run = true;
cout << "Would you like to [R]estart the game, [A]dd new score, [V]iew the score sheet or [Q]uit?" << endl;
cin >> respond;
switch (respond)
{
case 'R': m_game.play(); break;
case 'A': //add new score to fstream
case 'V': //view score txt file
case 'Q': run = false; break;
}
}
I am pretty confused about how to create the default constructor for this section, even with the examples from the book.
The constructor for the Game class looks like:
class Game
{
public:
Game(const vector<string>& names);
~Game();
//plays game
void play();
private:
Deck m_deck;
House m_house;
vector<Player> m_players;
};
I'm hoping to get an explanation or example. Thank you for your help!