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

      <small id='5FqXv'></small><noframes id='5FqXv'>

      <tfoot id='5FqXv'></tfoot>

        C++ 成员函数与自由函数

        C++ Member Functions vs Free Functions(C++ 成员函数与自由函数)

          <tbody id='AheIj'></tbody>

        • <small id='AheIj'></small><noframes id='AheIj'>

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

                  <tfoot id='AheIj'></tfoot>
                1. 本文介绍了C++ 成员函数与自由函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在编写程序时,很多时候我一直对这个设计决定感到困惑,但我不能 100% 确定何时应该使函数成为类的成员函数,何时离开它作为一个普通函数,当函数声明在头文件中公开时,其他源文件可以调用该函数.大多数情况下,对类成员变量的期望访问是否与决策有关?

                  解决方案

                  界面原理 by Herb Sutter

                  对于类 X,所有函数,包括自由函数,都
                  (a) 提及"X,和
                  (b) 随附" X
                  逻辑上是 X 的一部分,因为它们构成 X 接口的一部分.

                  有关深入讨论,请阅读 Herb Sutter 的命名空间和接口原则.>

                  编辑
                  实际上,如果您想了解 C++,请阅读所有内容 Herb Sutter 写的内容:)

                  I keep on getting confused about this design decision a lot of the time when I'm writing programs, but I'm not 100% sure when I should make a function to be a member function of a class, when to leave it as a normal function in which other source files can call the function when the function declaration is exposed in a header file. Does the desired access to member variables of a class have to do with the decision most of the time?

                  解决方案

                  The Interface Principle by Herb Sutter

                  For a class X, all functions, including free functions, that both
                  (a) "mention" X, and
                  (b) are "supplied with" X
                  are logically part of X, because they form part of the interface of X.

                  For in depth discussion read Namespaces and the Interface Principle by Herb Sutter.

                  EDIT
                  Actually, if you want to understand C++ go and read everything what Herb Sutter has written :)

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

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

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

                          <tfoot id='PGvkC'></tfoot>
                            <bdo id='PGvkC'></bdo><ul id='PGvkC'></ul>