【问题标题】:Why I'am getting this error? [closed]为什么我收到此错误? [关闭]
【发布时间】:2013-05-20 14:00:00
【问题描述】:
C:\Users\Victor\Desktop\0.3.r5958\luascript.cpp|9037|error: 'buttonEnter' may be used uninitialized in this function|
C:\Users\Victor\Desktop\0.3.r5958\luascript.cpp|9037|error: 'buttonEscape' may be used uninitialized in this function|
C:\Users\Victor\Desktop\0.3.r5958\luascript.cpp|9039|error: 'popup' may be used uninitialized in this function|
||=== Build finished: 3 errors, 0 warnings ===|strong text

这是我得到错误的行:

    std::string str, title, message;
    uint8_t buttonEnter, buttonEscape;
    std::vector<ModalChoice> buttons, choices;
    bool popup;

我正在使用 c++ 并尝试在代码块中编译

【问题讨论】:

  • 这家伙被stackoverflow.com/questions/12958931/… 否决的原因可能与您甚至没有提及您使用的语言相同。
  • 只读取编译器错误。它准确地告诉你发生了什么。
  • 对不起,我只是在学习语言
  • 是的 - 你还没有初始化它们。
  • 我要说...因为你还没有初始化它们。

标签: c++ compiler-errors


【解决方案1】:

你已经声明了你的对象和变量,但是你还没有初始化它们。 bool popup 只是声明您将使用名称为popup 的布尔值,但它不会初始化它。初始化意味着设置一个初始值,在本例中为truefalse

通常声明和初始化是一起完成的,例如bool popup = true;。如果您不初始化您的值,则行为未定义。有时某些编译器会实现默认值,但这值得依赖。如果你不这样做,你应该假设你会得到垃圾值。

【讨论】:

  • 谢谢,很抱歉这篇文章,但我正在学习语言
【解决方案2】:

不确定您使用的是哪种语言。但我认为这是因为您声明了它们,但没有定义它们,即给它们默认值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    相关资源
    最近更新 更多