I have three .cpp files: Game, Guesser, and Provider. Each one of the header files for those contains its respective class declaration.
In my Game class, I need private variables for Guesser and Provider.
Guesser has a non-default constructor
Guesser::Guesser (int wordLength, const char* wordListFilename){}
so I have to initialize it through an initialization list on the Game constructor.
What I have so far:
Guesser& guesser;
Provider& provider;
`Game::Game(int& wordLength, const char* filename, const Provider& providr) : guesser(wordLength, filename),provider(providr)
{
numMissedGuesses = 0;
wordSoFar = string(wordLength, FILL_CHARACTER);
}`
This code doesn't compile, and I'm lost on where to go from here.
Error messages from compiler:
||=== Build: Debug in adthangman (compiler: GNU GCC Compiler) ===|
error: 'guesser' declared as reference but not initialized|
error: 'provider' declared as reference but not initialized|
In constructor 'Game::Game(int, const char*, const Provider&)':|
error: expression list treated as compound expression in mem-initializer [-fpermissive]| warning: left operand of comma operator has no effect [-Wunused-value]|
error: invalid initialization of reference of type 'Guesser&' from expression of type 'const char*'|
error: invalid initialization of reference of type 'Provider&' from expression of type 'const Provider'| ||=== Build failed: 5 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Any help is greatly appreciated.
guessershouldn't be a reference. - 0x499602D2guesseris that the type is incomplete. The compiler is pretty clear onprovider. - chris