Why does “template argument deduction for class templates” not work on a plain struct?

依然范特西╮ 提交于 2019-12-11 06:02:02

问题


C++17 supports template argument deduction for class templates.

Please see www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0091r3.html for detailed background information.

However, the code below doesn't work as expected;

#include <utility>

template<typename T>
struct A
{
    T x;
};

int main()
{
    auto p = std::pair{ 1, 2 }; // ok, as expected.

    auto a = A{ 0 };
    //
    // error : no viable constructor or deduction guide
    // for deduction of template arguments of 'A'
    //
}

My compiler is clang 5.0 with -std=c++1z.

Why does template argument deduction for class templates not work on a plain struct?

来源:https://stackoverflow.com/questions/43019240/why-does-template-argument-deduction-for-class-templates-not-work-on-a-plain-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!