开发者

syntax error : missing ';' before identifier

I am new to c++, trying to debug the following line of code

class cGameError
{
    string m_errorText;
    public:
        cGameError( char *errorText )开发者_如何学JAVA
        {
            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"


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.


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>.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜