Send to a Friend

HeroicZach's avatar

Why does C++ not allow me to use strings in a class header file?

Asked by HeroicZach (195points) September 20th, 2009

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.

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.