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

      <small id='0wfMc'></small><noframes id='0wfMc'>

        • <bdo id='0wfMc'></bdo><ul id='0wfMc'></ul>
      1. <tfoot id='0wfMc'></tfoot>

        <legend id='0wfMc'><style id='0wfMc'><dir id='0wfMc'><q id='0wfMc'></q></dir></style></legend>

        struct, typedef struct, 在 C++ 中的用途

        Purpose of struct, typedef struct, in C++(struct, typedef struct, 在 C++ 中的用途)

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

          <tfoot id='sd9kj'></tfoot>
            • <bdo id='sd9kj'></bdo><ul id='sd9kj'></ul>

                <tbody id='sd9kj'></tbody>
                • <small id='sd9kj'></small><noframes id='sd9kj'>

                  本文介绍了struct, typedef struct, 在 C++ 中的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 C++ 中可以创建一个结构体:

                  In C++ it is possible to create a struct:

                  struct MyStruct
                  {
                      ...
                  }
                  

                  也可以执行以下操作:

                  typedef struct
                  {
                      ...
                  } MyStruct;
                  

                  但据我所知,两者之间没有明显区别.哪个更可取?如果没有区别,为什么两种方式都存在?一个在风格或可读性上比另一个更好吗?

                  And yet as far as I can tell, no discernable difference between the two. Which is preferable? Why do both ways exist if there is no difference? Is one better than the other in style or readability?

                  推荐答案

                  typedef 版本是

                  The typedef version is a special case of

                  typedef foo bar;
                  

                  定义了一个新的类型"栏作为 foo 的别名.在您的情况下, foo 恰好是一个结构.在 C 中,这是引入新类型"的唯一方法(在引号中,因为它们并不真正等同于 int、float 和 co).在 C++ 中,这不是那么有用,因为 C++ 旨在使新类型的定义比 C 更容易和更完整(至少在 C++ 开始时),并且 typedef 甚至不需要引用先前声明的结构(或班级).

                  which defines a new "type" bar as an alias for foo. In your case, foo happens to be a struct. In C, this was the only way to introduce new "types" (in quotes, because they are not really equivalent to int, float and co). In C++, this is not so useful, because C++ was designed to make definition of new types easier and more complete than C (at least at the beginnings of C++), and the typedef is not even necessary to refer to a previously declared struct (or class).

                  这篇关于struct, typedef struct, 在 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++程序中的堆栈溢出错误)

                  <tfoot id='4Tqoj'></tfoot>
                  <legend id='4Tqoj'><style id='4Tqoj'><dir id='4Tqoj'><q id='4Tqoj'></q></dir></style></legend>
                    <bdo id='4Tqoj'></bdo><ul id='4Tqoj'></ul>
                      <tbody id='4Tqoj'></tbody>

                        • <small id='4Tqoj'></small><noframes id='4Tqoj'>

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