如何为我的自定义模板类制作唯一的 ptr [重复]

问题描述 投票:0回答:0

这里代码:


template <typename First, typename Second>
struct pair
{
    First key;
    Second value;
};

template <typename F, typename S>
using slot= std::unique_ptr<pair<F,S>>;

int main()
{
    slot<int, char> abc[100];
    abc[2] = std::make_unique<pair<int, char>>(new pair<int, char>{ 5,3 });
    for (auto& i : abc)
    {
        i.reset();
    }
    auto& a = abc;


};

它给出错误:

Severity    Code    Description Project File    Line    Suppression State
Error   C2665   'pair<int,char>::pair': no overloaded function could convert all the argument types

我想要插槽容器,在这个示例代码中,我试图理解为什么 make_unique 给出错误... 为什么?以及如何让 unique_ptr 为我的班级工作

c++ templates smart-pointers
© www.soinside.com 2019 - 2024. All rights reserved.