Reputation: 10790
I am new to c++, trying to debug the following line of code
class cGameError
{
string m_errorText;
public:
cGameError( char *errorText )
{
DP1("***\n*** [ERROR] cGameError thrown! text: [%s]\n***\n",
errorText );
m_errorText = string( errorText );
}
const char *GetText()
{
return m_errorText.c_str();
}
};
enum eResult
{
resAllGood = 0, // function passed with flying colors
resFalse = 1, // function worked and returns 'false'
resFailed = –1, // function failed miserably
resNotImpl = –2, // function has not been implemented
resForceDWord = 0x7FFFFFFF
};
This header file is included in the program as followed
#include "string.h"
#include "stdafx.h"
#include "Chapter 01 MyVersion.h"
#include "cGameError.h"
Upvotes: 1
Views: 2382
Reputation: 6833
You need to include <string>, not "string.h". Or in addition to "string.h".
string.h is the C header for the standard C string handling functions (strcpy() and friends.)
<string> is the standard C++ header where 'string' is defined.
You also need to specify the std namespace when using string:
std::string m_errorText;
Or by using:
using namespace std;
Somewhere at the top of your file.
You should also use angle brackets for system include files.
Upvotes: 4
Reputation: 3686
Try #include <string>
, instead of #include "string.h"
, string.h/cstring is the old C-string header, string is the new C++ std::string
class header. And you normally use angle-brackets for system headers.
Upvotes: 1
Reputation: 490118
You've provided little enough information that this is only a wild guess, but at first glance, I'd guess the problem is that you haven't included <string>
, only "string.h"
(the former defines the C++ std::string
class, the latter the C functions for manipulating nul-terminated strings.
As an aside, you normally want to use angle-brackets for system headers, so it should be <string.h>
.
Upvotes: 1