Reputation: 3172
I am building a class in a header file (declarations) and a .cpp file (Definitions). In the "private" part I have a
string m_name
The compiler gives me an error when I try to compile it. If I replace the string with a char* it works fine. I do, however, need a string, not a char*. Should I add the string header somewhere or something ?
Thanks in advance.
Upvotes: 0
Views: 188
Reputation: 1673
If you want to use string, you basically need to include its header file #include <string.h>
for C or #include <cstring>
for C++, otherwise you will get errors.
Upvotes: 1
Reputation:
I suspect two problems: one, "Should I add the string header somewhere?" - you should
#include <string>
Two, if you're not using namespace std;
, then you have to use the fully qualified name of the class, which is std::string
and not just string
.
Upvotes: 1
Reputation: 110738
Make sure you #include <string>
at the top of your header file and remember that it's within the std
namespace: std::string m_name;
.
Upvotes: 2