<small id='LMBEj'></small><noframes id='LMBEj'>

    1. <i id='LMBEj'><tr id='LMBEj'><dt id='LMBEj'><q id='LMBEj'><span id='LMBEj'><b id='LMBEj'><form id='LMBEj'><ins id='LMBEj'></ins><ul id='LMBEj'></ul><sub id='LMBEj'></sub></form><legend id='LMBEj'></legend><bdo id='LMBEj'><pre id='LMBEj'><center id='LMBEj'></center></pre></bdo></b><th id='LMBEj'></th></span></q></dt></tr></i><div id='LMBEj'><tfoot id='LMBEj'></tfoot><dl id='LMBEj'><fieldset id='LMBEj'></fieldset></dl></div>

        <bdo id='LMBEj'></bdo><ul id='LMBEj'></ul>
      1. <legend id='LMBEj'><style id='LMBEj'><dir id='LMBEj'><q id='LMBEj'></q></dir></style></legend><tfoot id='LMBEj'></tfoot>

        “Y 未命名类型"C++ 中的错误

        quot;Y does not name a typequot; error in C++(“Y 未命名类型C++ 中的错误)

        <tfoot id='wepxa'></tfoot>

            <tbody id='wepxa'></tbody>

          • <i id='wepxa'><tr id='wepxa'><dt id='wepxa'><q id='wepxa'><span id='wepxa'><b id='wepxa'><form id='wepxa'><ins id='wepxa'></ins><ul id='wepxa'></ul><sub id='wepxa'></sub></form><legend id='wepxa'></legend><bdo id='wepxa'><pre id='wepxa'><center id='wepxa'></center></pre></bdo></b><th id='wepxa'></th></span></q></dt></tr></i><div id='wepxa'><tfoot id='wepxa'></tfoot><dl id='wepxa'><fieldset id='wepxa'></fieldset></dl></div>
              • <bdo id='wepxa'></bdo><ul id='wepxa'></ul>

                <small id='wepxa'></small><noframes id='wepxa'>

                <legend id='wepxa'><style id='wepxa'><dir id='wepxa'><q id='wepxa'></q></dir></style></legend>

                1. 本文介绍了“Y 未命名类型"C++ 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我不知道要搜索什么才能找到对此的解释,所以我在问.
                  我有这个报告错误的代码:

                  I don't know what to search to find an explanation for this, so I am asking.
                  I have this code which reports error:

                  struct Settings{
                      int width;
                      int height;
                  } settings;
                  
                  settings.width = 800; // 'settings' does not name a type error
                  settings.height = 600; // 'settings' does not name a type error
                  
                  int main(){
                      cout << settings.width << " " << settings.height << endl;
                  

                  但是如果我将值赋值放在 main 中,它会起作用:

                  but if I put the value assignment in main, it works:

                  struct Settings{
                      int width;
                      int height;
                  } settings;
                  
                  main () {
                      settings.width = 800; // no error
                      settings.height = 600; // no error
                  

                  你能解释一下为什么吗?

                  Can you explain me why?


                  关于 Ralph Tandetzky 的回答,这是我的完整结构代码.你能告诉我如何像你对我的代码片段结构一样分配值吗?


                  Regarding to Ralph Tandetzky's answer, here is my full struct code. Could you show me how to assign the values as you did with my snippet struct?

                  struct Settings{
                      struct Dimensions{
                          int width;
                          int height;
                      } screen;
                  
                      struct Build_menu:Dimensions{
                          int border_width;
                      } build_menu;
                  } settings;
                  

                  推荐答案

                  在 C++ 中,不能将赋值放在函数的上下文之外.如果您对有时在函数上下文之外使用 = 符号这一事实感到困惑,例如:

                  You cannot put assignments outside the context of a function in C++. If you're puzzled by the fact that you sometimes saw the = symbol being used outside the context of a function, such as:

                  int x = 42; // <== THIS IS NOT AN ASSIGNMENT!
                  
                  int main()
                  {
                      // ...
                  }
                  

                  那是因为 = 符号也可以用于初始化.在您的示例中,您没有初始化数据成员 widthheight,而是为它们分配了一个值.

                  That's because the = symbol can be used for initialization as well. In your example, you are not initializing the data members width and height, you are assigning a value to them.

                  这篇关于“Y 未命名类型"C++ 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                  • <i id='e7B5U'><tr id='e7B5U'><dt id='e7B5U'><q id='e7B5U'><span id='e7B5U'><b id='e7B5U'><form id='e7B5U'><ins id='e7B5U'></ins><ul id='e7B5U'></ul><sub id='e7B5U'></sub></form><legend id='e7B5U'></legend><bdo id='e7B5U'><pre id='e7B5U'><center id='e7B5U'></center></pre></bdo></b><th id='e7B5U'></th></span></q></dt></tr></i><div id='e7B5U'><tfoot id='e7B5U'></tfoot><dl id='e7B5U'><fieldset id='e7B5U'></fieldset></dl></div>
                      <legend id='e7B5U'><style id='e7B5U'><dir id='e7B5U'><q id='e7B5U'></q></dir></style></legend><tfoot id='e7B5U'></tfoot>
                    • <small id='e7B5U'></small><noframes id='e7B5U'>

                            <tbody id='e7B5U'></tbody>
                            <bdo id='e7B5U'></bdo><ul id='e7B5U'></ul>