Код: Выделить всё
#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;
}
В чем проблема в примерах 2 и 4? Как их исправить?
Большое спасибо за вашу помощь!
Подробнее здесь: https://stackoverflow.com/questions/703 ... ake-unique