АВТОМАТИЧЕСКИЙ ПАРАМУКЦИИ ПАРАМЕКЦИИ В УНИКУСПОЛЬНОЙ_PTR и MAKE_UNIQUEC++

Программы на C++. Форум разработчиков
Anonymous
АВТОМАТИЧЕСКИЙ ПАРАМУКЦИИ ПАРАМЕКЦИИ В УНИКУСПОЛЬНОЙ_PTR и MAKE_UNIQUE

Сообщение Anonymous »

Почему я получаю автоматическое вычет параметров шаблона, если я вызову конструктор класса напрямую, но я не получаю его в std :: ulious_ptr и std :: make_unique ? Вот пример: < /p>

Код: Выделить всё

#include 
template 
class C
{
public:
C(const T * const t_) : t(t_) {}
~C(void) { delete t; }
private:
const T * const t;
};
< /code>
Пример 1 (работает): < /p>
int main(void)
{
const int * const t = new int;
auto * const c = new C(t);
return 0;
}
< /code>
Пример 2 (не компилируется): < /p>
int main(void)
{
const int * const t = new int;
auto * const c = new C(t);
std::unique_ptr p(c); // class template argument deduction failed
return 0;
}
< /code>
Пример 3 (работает): < /p>
int main(void)
{
const int * const t = new int;
const auto c = std::make_unique(t);
return 0;
}
< /code>
Пример 4 (не компилируется): < /p>
int main(void)
{
const int * const t = new int;

// no matching function for call to ‘make_unique(const int* const&)
const auto c = std::make_unique(t);
return 0;
}
Код был составлен с G ++ -Std = C ++ 17 (GCC -11.2.0).
В чем проблема в примерах 2 и 4? Как их исправить?
Большое спасибо за вашу помощь!

Подробнее здесь: https://stackoverflow.com/questions/703 ... ake-unique

Вернуться в «C++»