General Question
Why does C++ not allow me to use strings in a class header file?
I have code that looks like this:
public:
myClass(string inWord); // value constructor
Up above the class in the class header file, I have #include <string>, so C++ should know what I’m talking about. Unfortunately, I ALWAYS get this error message:
15 myClass.h expected `)’ before “inWord”
Further down in the class, I have:
bool myFunction(string guessWord);
but I get the following error message:
22 myClass.h expected `;’ before ’(’ token
Why is this happening? If I comment out all the references to string the program compiles, and even when I engage some back in, the program starts to compile – it’s only when I create the value constructor in the .cpp file that matches with this .h that the program explodes in errors. Even when I comment out the value constructor implementation in the .cpp file, clean, then recompile, it still explodes in errors until I remove all string references.
Your help is 110% greatly appreciated.
2 Answers
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.