Why can't unique_ptr's template arguments be deduced?

后端 未结 2 2005
后悔当初
后悔当初 2020-12-18 19:22

When you have class template argument deduction available from C++17, why can\'t you deduce the template arguments of std::unique_ptr? For example, this gives me an error:

2条回答
  •  时光取名叫无心
    2020-12-18 20:09

    Lets look at new int and new int[10]. Both of those return an int*. There is no way to tell if you should have unique_ptr or unique_ptr. That right there is enough not to provide any sort of deduction guide.

提交回复
热议问题