I think that you actually want to call the function instead of attempting to declare it:
Code:
string wordtbg::wtbg()
{
ifstream wordfile("words.txt", ios::in);
if (!wordfile)
{
cout << "could not get word from file :'( ";
wordtobeguessed = "";
}
else
{
getline(wordfile, wordtobeguessed);
cout << wordtobeguessed << endl; // just to verify it worked
}
return wordtobeguessed;
}
However, your class design looks a little awkward. I would suggest something like this:
Code:
class HangManWord
{
public:
// Initialise with the answer to be guessed.
explicit HangManWord(const std::string& answer);
// Returns true if letter is in the answer.
bool guess(char letter) const;
// Returns true if word is the answer.
bool guess(const std::string& word) const;
private:
std::string answer;
};
Then your current wtbg() member function would become a free function that say, returns a HangManWord object, or throws an exception if the file could not be opened. You could also provide a default constructor and a setter function if you think that it is necessary, and perhaps use a HangMan namespace so you have a HangMan::Word object instead.