I have a game class in which I want to initialize a vector of players: Please note that this has to be a reference: It goes like this:
#define GAME_H
#include "player.h"
#include <vector>
#include <iostream>
#include <iterator>
class game
{
public:
game();
~game();
player P;
std::vector<player>&gPlayerVec;
std::vector<player>gPlayerVecCopy;
void PlayGame();
};
#endif //GAME_H
I get the following error when I compile:
c:\mpgames2\pointer\game.cpp(9) : error C2758: 'gPlayerVec' : must be initialized in constructor base/member initializer list
c:\mpgames2\pointer\game.h(17) : see declaration of 'gPlayerVec'
c:\mpgames2\pointer\game.cpp(9) : error C2758: 'gPlayerVecCopy' : must be initialized in constructor base/member initializer list
c:\mpgames2\pointer\game.h(18) : see declaration of 'gPlayerVecCopy'
the game constructor is here:
game::game()
{
gPlayerVec.push_back(P);
}
What do I need to put in there to fix this problem