samedi 14 mars 2020

Use Members of One Class in Another Class (OOP)

I have two classes Instructor and Game.

Instructor.h

class Instructor
{
    int instrID;

public:
    Instructor();
    void showGameStatus();
    int createGame();                           
    vector<int> createGames(int numberOfGames); 
};

First, I have to create Games in the createGame() class. Is it possible to create a class inside a class? Next, In the instructor class, I have this method. I want that on calling this method, I show the corresponding Game class' details for example gId, InstrId etc.

void Instructor::showGameStatus()
{

}

This is how my Game looks like:

class Game {

private:                            
    int gID;                        
    int instrID;                    
    int pFactID;                    
public:

    Game() {                // default constructor
        gID = 0;
        instrID = 0;
        pFactID = 0;

    };

How can I link both of them now?

Aucun commentaire:

Enregistrer un commentaire