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

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

        在编译时检查类构造函数签名

        Check at compile time class constructor signature(在编译时检查类构造函数签名)
      2. <i id='LKOxU'><tr id='LKOxU'><dt id='LKOxU'><q id='LKOxU'><span id='LKOxU'><b id='LKOxU'><form id='LKOxU'><ins id='LKOxU'></ins><ul id='LKOxU'></ul><sub id='LKOxU'></sub></form><legend id='LKOxU'></legend><bdo id='LKOxU'><pre id='LKOxU'><center id='LKOxU'></center></pre></bdo></b><th id='LKOxU'></th></span></q></dt></tr></i><div id='LKOxU'><tfoot id='LKOxU'></tfoot><dl id='LKOxU'><fieldset id='LKOxU'></fieldset></dl></div>

          <tfoot id='LKOxU'></tfoot>

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

                <tbody id='LKOxU'></tbody>

                <legend id='LKOxU'><style id='LKOxU'><dir id='LKOxU'><q id='LKOxU'></q></dir></style></legend>
                  <bdo id='LKOxU'></bdo><ul id='LKOxU'></ul>
                  本文介绍了在编译时检查类构造函数签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法在编译时检查某个类是否具有带有某些参数的构造函数??

                  Is there a way to check at compile time if some class has constructor with certain arguments ? ?

                  例如:

                  class foo {
                      foo(std::string &s) {
                      }
                  };
                  

                  我想在编译时用 std::string& 检查构造函数.始终定义.或许 boost 提供了这样的功能?

                  I want to check at compile time that constructor with std::string& always defined. Maybe boost provides such functionality ?

                  推荐答案

                  检查特定函数是否存在的常用方法是获取其地址并将其分配给一个虚拟变量.这比目前提到的测试要精确得多,因为这可以验证确切的函数签名.问题特别是关于签名中的 string& ,因此非常量,因此可能会修改字符串.

                  The common way to check if a specific function exists is to take its address and assign it to a dummy variable. This is a lot more precise than the tests mentioned so far, because this verifies the exact function signature. And the question was specifically about string& in the signature, so non-const and thus presumably modifying the string.

                  但是,在这种情况下,您不能使用获取地址并分配它的技巧:构造函数没有地址.那么,你如何检查签名呢?简单地说:在虚拟课程中与它成为朋友.

                  However, in this case you cannot use the take-the-address-and-assign-it trick: constructors don't have addresses. So, how do you check the signature then? Simply: Befriend it in a dummy class.

                  template<typename T>
                  class checkSignature_StringRef {
                      friend T::T(string&);
                  };
                  

                  这也是一个非常具体的检查:它甚至不会匹配类似的构造函数,例如 foo::foo(std::string &s, int dummy = 0).

                  This too is a very specific check: it will not even match similar constructors like foo::foo(std::string &s, int dummy = 0).

                  这篇关于在编译时检查类构造函数签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

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

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

                              <tbody id='S4tHc'></tbody>

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

                          • <legend id='S4tHc'><style id='S4tHc'><dir id='S4tHc'><q id='S4tHc'></q></dir></style></legend>