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

      <bdo id='G3tRM'></bdo><ul id='G3tRM'></ul>
    <legend id='G3tRM'><style id='G3tRM'><dir id='G3tRM'><q id='G3tRM'></q></dir></style></legend>
    1. <small id='G3tRM'></small><noframes id='G3tRM'>

      <tfoot id='G3tRM'></tfoot>

      C++ 中类与函数的模板类型推导?

      时间:2023-05-24

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

    2. <tfoot id='QJyHm'></tfoot>
      <legend id='QJyHm'><style id='QJyHm'><dir id='QJyHm'><q id='QJyHm'></q></dir></style></legend>
        <tbody id='QJyHm'></tbody>

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

                本文介绍了C++ 中类与函数的模板类型推导?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                为什么自动类型推导只能用于函数而不能用于类?

                Why is that automatic type deduction is possible only for functions and not for Classes?

                推荐答案

                在特定情况下,你总是可以像 std::make_pair:

                In specific cases you could always do like std::make_pair:

                template<class T>
                make_foo(T val) {
                    return foo<T>(val);
                }
                

                我刚刚在C++ 编程语言,第三版",第 335 页中找到了以下内容.Bjarne 说:

                I just found the following in "The C++ Programming Language, Third Edition", page 335. Bjarne says:

                请注意,类模板参数是从未推断.原因是几个提供的灵活性类的构造函数将使这种扣除在很多情况下是不可能的案例和模糊的更多.

                Note that class template arguments are never deduced. The reason is that the flexibility provided by several constructors for a class would make such deduction impossible in many cases and obscure in many more.

                这当然是非常主观的.在comp.std.c++ 中对此进行了一些讨论,共识似乎是没有理由不支持它.这是否是一个好主意是另一个问题...

                This is of course very subjective. There's been some discussion about this in comp.std.c++ and the consensus seems to be that there's no reason why it couldn't be supported. Whether it would be a good idea or not is another question...

                这篇关于C++ 中类与函数的模板类型推导?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:C++11 类型特征来区分枚举类和常规枚举 下一篇:模板元程序将类型转换为唯一编号

                相关文章

                最新文章

              1. <small id='32NgS'></small><noframes id='32NgS'>

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

                  • <bdo id='32NgS'></bdo><ul id='32NgS'></ul>

                  1. <tfoot id='32NgS'></tfoot>