我的节目造反了吗?未进行更改

时间:2018-08-22 21:43:55

标签: c++ visual-studio

我在Visual Studio中遇到一个烦人的问题。确实,我正在设计编译器,并且为错误消息保留了一个文件。它可与字典(std :: map):代码→消息一起使用。

但是,对字典所做的更改似乎并不影响程序,该程序的反应就像没有进行任何更改。

我很难用单词更清楚地解释,所以我记录了a video。 (它不属于该网站,抱歉,我没有找到如何将其包括在这篇文章中。)

如您所见,我们使用一个函数来显示错误消息,该错误消息是从字典中获取的:

std::map<ErrorCodes, std::string> Messages;
...
std::string ErrMessage = Messages[code];

我不明白为什么所做的更改不会按预期影响程序。似乎Visual Studio不再编译部分代码...

实际上,在记录中,我们可以看到控制台中显示的错误消息是[E29](在[E80]之前的旧消息),并且显示的消息不是与枚举相对应的消息。要么。

这个问题看似简单,但老实说我看不出它可能在哪里...

编辑:

这是更详细的说明:

在视频中,控制台中运行的程序是我的。 “编译未成功”是我自己的错误消息,通常会显示出来。

这是错误呼叫显示的呼叫代码:

exception.ThrowError(exception.E0080);

E0080是错误列表代码,这是错误消息文件:

*。hpp:

class Exception {
public:
    enum ErrorCodes {
        E0000,
        E0001, //  Can't load file
        E0002, //  Can't find header file
        E0003, //  Expected file name
        E0004, //  Unexpected token
        E0005, //  Expected Identifier
        E0006, //  Value without storage object
        E0007, //  Already existing object
        E0008, //  Redefined preprocessor definition
        E0009, //  Redefined variable
        E0010, //  Redefined function
        E0011, //  Redefined object
        E0012, //  Redefined rule
        E0013, //  Redefined value
        E0014, //  Undefined identifier
        E0015, //  Buoyage symbol missing
        E0016, //  Expected end of line symbol (';')
        E0017, //  Unexpected character
        E0018, //  Unknown token
        E0019, //  Non-close comment
        E0020, //  Non-compliant typing
        E0021, //  Use of uninitialized data
        E0022, //  Unacceptable suffix
        E0023, //  Invalid keyword combination
        E0024, //  Declaration not in accordance with non-local use
        E0025, //  Incompatible value with type / object defined
        E0026, //  Constant value too wide
        E0027, //  Too much initialization value in a static size array
        E0028, //  Non-conforming identifier
        E0029, //  Expected statement
        E0030, //  Wrong identifier format (the expected format is ASCII)
        E0031, //  Wrong pointer initialization
        E0032, //  Non-valid literal suffix
        E0033, //  No object can have the identifier 'vanaur'
        E0034, //  Non-existent object field
        E0035, //  Non-existent object method
        E0036, //  Missing function call arguments
        E0037, //  A rvalue cannot be accessed via the pointers
        E0038, //  The use of a pointer is unacceptable in this context
        E0039, //  A reference cannot be made to a constant value
        E0040, //  Invalid assembler code in external expression
        E0041, //  The types of the two objects do not match in the image assignment
        E0042, //  Only a defined object can be destroyed by the delete operator
        E0043, //  Empty template
        E0044, //  Object not existing in this namespace
        E0045, //  Typage temptation with a non-instanciated structure
        E0046, //  Temptation to access a private field of the object
        E0047, //  Temptation to access a private method of the object
        E0048, //  Invalid operator
        E0049, //  Reserved identifier
        E0050, //  Wrong usage of postfix and prefix operator
        E0051, //  Temptation to access an inaccessible element in a table
        E0052, //  The main function can only have 3 arguments variation
        E0053, //  This function is not defined as being able to return an array
        E0054, //  A non-instanciated structure cannot be used as an object instance with the keyword 'new'.
        E0055, //  Wrong choice of the anonymous string concatenation operator (between '^' and'+')
        E0056, //  An object can only inherit from one other object
        E0057, //  Incorrect 'typename' value
        E0058, //  Incorrect 'typesize' value
        E0059, //  The identifier of a process ('proc') cannot contain spaces
        E0060, //  The identifier of a process ('proc') cannot contain balises
        E0061, //  An exception cannot be thrown out of a function
        E0062, //  Syntax error
        E0063, //  The increment value of an iteration (with step) must be numerical
        E0064, //  An anonymous array serving as an iterator to a for loop cannot be empty
        E0065, //  Wrong ternary condition format
        E0066, //  A 'ret' instruction must only fit on one instruction (one line = one ';')
        E0067, //  Division by zero
        E0068, //  Wrong enumeration value
        E0069, //  'Upon' block members cannot contain expressions other than 'it'
        E0070, //  A match/case expression must contain at least one 'case' expression before using 'default'
        E0071, //  Unknown error
        E0072, //  Undefined object
        E0073, //  Not a valid math expression
        E0074, //  Expected character
        E0075, //  Unbalanced brackets
        E0076, //  Non-ascii character detected
        E0077, //  The current version of Arlia only accepts constant values as optional function parameters
        E0078, //  Undefined type
        E0079, //  Statement not recognised in this context
        E0080, //  Invalid statement
    };
    void ThrowError(ErrorCodes, char);
    void ThrowError(ErrorCodes, std::string);
    void ThrowError(ErrorCodes, token_t);
    void ThrowError(ErrorCodes, token_t, Expr);
    void ThrowError(ErrorCodes, Expr);
private:
    std::map<ErrorCodes, std::string> Messages =
    {
        { E0001, " Can't load file" },
    { E0002, " Can't find header file" },
    { E0003, " Expected file name" },
    { E0004, " Unexpected token" },
    { E0005, " Expected Identifier" },
    { E0006, " Value without storage object" },
    { E0007, " Already existing object" },
    { E0008, " Redefined preprocessor definition" },
    { E0009, " Redefined variable" },
    { E0010, " Redefined function" },
    { E0011, " Redefined object" },
    { E0012, " Redefined rule" },
    { E0013, " Redefined value" },
    { E0014, " Undefined identifier" },
    { E0015, " Buoyage symbol missing" },
    { E0016, " Expected end of line symbol (';')" },
    { E0017, " Unexpected character" },
    { E0018, " Unknown token" },
    { E0019, " Non-close comment" },
    { E0020, " Non-compliant typing" },
    { E0021, " Use of uninitialized data" },
    { E0022, " Unacceptable suffix" },
    { E0023, " Invalid keyword combination" },
    { E0024, " Declaration not in accordance with non-local use" },
    { E0025, " Incompatible value with type / object defined" },
    { E0026, " Constant value too wide" },
    { E0027, " Too much initialization value in a static size array" },
    { E0028, " Non-conforming identifier" },
    { E0029, " Expected statement" },
    { E0030, " Wrong identifier format (the expected format is ASCII)" },
    { E0031, " Wrong pointer initialization" },
    { E0032, " Non-valid literal suffix" },
    { E0033, " No object can have the identifier 'vanaur'" },
    { E0034, " Non-existent object field" },
    { E0035, " Non-existent object method" },
    { E0036, " Missing function call arguments" },
    { E0037, " A rvalue cannot be accessed via the pointers" },
    { E0038, " The use of a pointer is unacceptable in this context" },
    { E0039, " A reference cannot be made to a constant value" },
    { E0040, " Invalid assembler code in external expression" },
    { E0041, " The types of the two objects do not match in the image assignment" },
    { E0042, " Only a defined object can be destroyed by the delete operator" },
    { E0043, " Empty template" },
    { E0044, " Object not existing in this namespace" },
    { E0045, " Typage temptation with a non-instanciated structure" },
    { E0046, " Temptation to access a private field of the object" },
    { E0047, " Temptation to access a private method of the object" },
    { E0048, " Invalid operator" },
    { E0049, " Reserved identifier" },
    { E0050, " Wrong usage of postfix and prefix operator" },
    { E0051, " Temptation to access an inaccessible element in a table" },
    { E0052, " The main function can only have 3 arguments variation" },
    { E0053, " This function is not defined as being able to return an array" },
    { E0054, " A non-instanciated structure cannot be used as an object instance with the keyword 'new'" },
    { E0055, " Wrong choice of the anonymous string concatenation operator (between '^' and'+')" },
    { E0056, " An object can only inherit from one other object" },
    { E0057, " Incorrect 'typename' value" },
    { E0058, " Incorrect 'typesize' value" },
    { E0059, " The identifier of a process ('proc') cannot contain spaces" },
    { E0060, " The identifier of a process ('proc') cannot contain balises" },
    { E0061, " An exception cannot be thrown out of a function" },
    { E0062, " Syntax error" },
    { E0063, " The increment value of an iteration (with step) must be numerical" },
    { E0064, " An anonymous array serving as an iterator to a for loop cannot be empty" },
    { E0065, " Wrong ternary condition format" },
    { E0066, " A 'ret' instruction must only fit on one instruction (one line = one ';')" },
    { E0067, " Division by zero" },
    { E0068, " Wrong enumeration value" },
    { E0069, " 'Upon' block members cannot contain expressions other than 'it'" },
    { E0070, " A match/case expression must contain at least one 'case' expression before using 'default'" },
    { E0071, " Unknown error" },
    { E0072, " Undefined object" },
    { E0073, " Not a valid math expression" },
    { E0074, " Expected character" },
    { E0075, " Unbalanced brackets" },
    { E0076, " Non-ascii character detected" },
    { E0077, " The current version of Arlia only accepts constant values as optional function parameters" },
    { E0078, " Undefined type" },
    { E0079, " Statement not recognised in this context" },
    { E0080, " Invalid statement" },

    { E0000, " ... " }
    };
};

*。cpp仅实现以下功能:

ThrowError(ErrorCodes code) {
    colored_message_error("[ E" + std::to_string(code) + " ]" + Messages[code], Color::yellow);
}

如您所见,该列表包含80 + 1个元素。 E0080的枚举索引为80。

当我尝试访问它时:

exception.ThrowError(exception.E0080);

我的程序似乎不想更新信息。也就是说,发送给该函数的枚举常量:实际上,程序会显示我在它之前设置的值(E29)。

就像我在做这个一样:

exception.ThrowError(exception.E0029);

所以,不,这很可能不是愚蠢的调试或编译问题(我仍然知道如何使用编译器^^)。 Visual Studio不更新此新数据似乎很奇怪(为什么?为什么?)。

0 个答案:

没有答案