0

EclipseでC++アプリケーションを書いていますが、コードを書いているときに、ch_type.cppの18、27、41、81行目にいくつかのバグが見つかりました。これが私のプロジェクトの現在のコードです:

ch_type.h

/********************************************************
 * char_type -- Character type class            *
 *                          *
 * Member functions:                    *
 *  type -- returns the type of a character     *
 *      (Limited to simple types)       *
 *  is(ch, char_type) -- check to see if ch is  *
 *      a member of the given type.     *
 *      (Works for derrived types as well.) *
 *******************************************************/
class char_type {
    public:
        enum CHAR_TYPE {
            C_EOF,      // End of file character
            C_WHITE,    // Whitespace or control character
            C_NEWLINE,  // A Newline character
            C_ALPHA,    // A Letter (includes _)
            C_DIGIT,    // A number
            C_OPERATOR, // Random operator
            C_SLASH,    // The character '/'
            C_L_PAREN,  // The character '('
            C_R_PAREN,  // The character ')'
            C_L_CURLY,  // The character '{'
            C_R_CURLY,  // The character '}'
            C_SINGLE,   // The character '\''
            C_DOUBLE,   // The character '"'
            // End of simple types, more complex, derrived types follow
            C_HEX_DIGIT,    // Hexidecimal digit
            C_ALPHA_NUMERIC // Alpha numeric
        };
    private:
        static enum CHAR_TYPE  type_info[256];      // information of each character

        // Fill in a range of type info stuff
        void fill_range(int start, int end, CHAR_TYPE type);
    public:
        char_type();    // Initialize the data
            //~char_type -- default destructor

            // Returns true if character is a given type
            int is(int ch, CHAR_TYPE kind);

            CHAR_TYPE type(int ch);
        }

ch_type.cpp

/********************************************************
 * ch-type package                  *
 *                          *
 * The class ch_type is used to tell the type of    *
 * various characters                   *
 *                          *
 * The main number functions are:           *
 *  is -- True if the character is the indicated    *
 *      type.                   *
 *  type -- Return type of character.       *
 *******************************************************/
#include <iostream>
#include <assert.h>

#include "ch_type.h"

// Define the type information array
char_type::CHAR_TYPE char_type::type_info[256];
/********************************************************
 * fill_range -- fill in a range of types for the   *
 *  character type class                *
 *                          *
 * Parameters                       *
 *  start, end -- range of items to fill in     *
 *  type -- type to use for filling         *
 *******************************************************/
void char_type::fill_range(int start, int end, CHAR_TYPE type)
{
    int cur_ch;

    for (cur_ch = start; cur_ch <= end; ++cur_ch) {
        assert(cur_ch >= 0);
        assert(cur_ch < sizeof(type_info)/sizeof(type_info[0]));
        type_info[cur_ch] = type;
    }
}

/*********************************************************
 * char_type::char_type -- initialize the char type table*
 ********************************************************/
char_type::char_type()
{
    fill_range(0, 255, C_WHITE);

    fill_range('A', 'Z', C_ALPHA);
    fill_range('a', 'z', C_ALPHA);
    type_info['_'] = C_ALPHA;

    type_info['!'] = C_OPERATOR;
    type_info['#'] = C_OPERATOR;
    type_info['$'] = C_OPERATOR;
    type_info['%'] = C_OPERATOR;
    type_info['^'] = C_OPERATOR;
    type_info['&'] = C_OPERATOR;
    type_info['*'] = C_OPERATOR;
    type_info['-'] = C_OPERATOR;
    type_info['+'] = C_OPERATOR;
    type_info['='] = C_OPERATOR;
    type_info['|'] = C_OPERATOR;
    type_info['~'] = C_OPERATOR;
    type_info[','] = C_OPERATOR;
    type_info[':'] = C_OPERATOR;
    type_info['?'] = C_OPERATOR;
    type_info['.'] = C_OPERATOR;
    type_info['<'] = C_OPERATOR;
    type_info['>'] = C_OPERATOR;

    type_info['/'] = C_SLASH;
    type_info['\n'] = C_NEWLINE;

    type_info['('] = C_L_PAREN;
    type_info[')'] = C_R_PAREN;

    type_info['{'] = C_L_CURLY;
    type_info['}'] = C_R_CURLY;

    type_info['"'] = C_DOUBLE;
    type_info['\''] = C_SINGLE;
}

int char_type::is(int ch, CHAR_TYPE kind)
{
    if (ch == EOF) return (kind == C_EOF);

    switch (kind) {
        case C_HEX_DIGIT:

            assert(ch >= 0);
            assert(ch < sizeof(type_info)/sizeof(type_info[0]));

            if (type_info[ch] == C_DIGIT)
                return (1);

            if ((ch >= 'A') && (ch <= 'F'))
                return (1);
            if ((ch >= 'a') && (ch <= 'f'))
                return (1);
            return (0);
        case C_ALPHA_NUMERIC:
            assert(ch >= 0);
            assert(ch < sizeof(type_info)/sizeof(type_info[0]));

            return ((type_info[ch] == C_ALPHA) ||
                (type_info[ch] == C_DIGIT));
        default:
            assert(ch >= 0);
            assert(ch < sizeof(type_info)/sizeof(type_info[0]));

            return (type_info[ch] == kind);
        }
};

私は何を間違えましたか?これらのバグを修正するにはどうすればよいですか?

これは私のエラーメッセージです:

説明リソースパスロケーションタイプ

メンバー宣言が見つかりませんch_type.cpp/stats行18セマンティックエラー

4

1 に答える 1

4

まず、クラス定義の後に挿入する必要があります;

class char_type {
    ...
}; //HERE

次に、マクロを使用するには、EOF含める必要があります<stdio.h>

于 2013-02-06T01:20:24.757 に答える