<legend id='5wLuR'><style id='5wLuR'><dir id='5wLuR'><q id='5wLuR'></q></dir></style></legend>
    1. <small id='5wLuR'></small><noframes id='5wLuR'>

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

        未命名命名空间优于静态命名空间?

        Superiority of unnamed namespace over static?(未命名命名空间优于静态命名空间?)

          <tfoot id='jbqNE'></tfoot>
            • <bdo id='jbqNE'></bdo><ul id='jbqNE'></ul>
            • <small id='jbqNE'></small><noframes id='jbqNE'>

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

                  <legend id='jbqNE'><style id='jbqNE'><dir id='jbqNE'><q id='jbqNE'></q></dir></style></legend>
                  本文介绍了未命名命名空间优于静态命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  未命名命名空间如何优于 static 关键字?

                  How are unnamed namespaces superior to the static keyword?

                  推荐答案

                  您基本上是指 C++03 标准中的 §7.3.1.1/2 部分,

                  You're basically referring to the section §7.3.1.1/2 from the C++03 Standard,

                  static 关键字的使用是在声明对象时不推荐使用命名空间范围;这未命名命名空间提供了一个优越的替代.

                  The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative.

                  请注意,此段落已在 C++11 中删除.static 函数已按照标准 不再被弃用!

                  Note that this paragraph was already removed in C++11. static functions are per standard no longer deprecated!

                  尽管如此,未命名的 namespace 优于 static 关键字,主要是因为关键字 static 仅适用于 变量 声明和函数,而不是用户定义的类型.

                  Nonetheless, unnamed namespace's are superior to the static keyword, primarily because the keyword static applies only to the variables declarations and functions, not to the user-defined types.

                  以下代码在 C++ 中有效:

                  The following code is valid in C++:

                  //legal code
                  static int sample_function() { /* function body */ }
                  static int sample_variable;
                  

                  但此代码无效:

                  //illegal code
                  static class sample_class { /* class body */ };
                  static struct sample_struct { /* struct body */ };
                  

                  所以解决方案是,未命名(又名匿名)namespace,就是这样:

                  So the solution is, unnamed (aka anonymous) namespace, which is this:

                  //legal code
                  namespace 
                  {  
                       class sample_class { /* class body */ };
                       struct sample_struct { /* struct body */ };
                  }
                  

                  希望它能解释为什么未命名的namespace优于static.

                  Hope it explains that why unnamed namespace is superior to static.

                  这篇关于未命名命名空间优于静态命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)
                    <tbody id='n9IPe'></tbody>
                • <small id='n9IPe'></small><noframes id='n9IPe'>

                    <tfoot id='n9IPe'></tfoot>

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

                            <bdo id='n9IPe'></bdo><ul id='n9IPe'></ul>