Template type deduction in C++ for Class vs Function?

后端 未结 4 2055
难免孤独
难免孤独 2020-12-03 01:37

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 02:39

    At Kona meeting Template parameter deduction for constructors (P0091R0) has been approved, which means that in C++17 we'll be able to we can write:

    pair p1{"foo"s, 12};
    auto p2 = pair{"foo"s, 12};
    f(pair{"foo"s, 12});
    

提交回复
热议问题