试图引用已删除的函数的Visual C ++ 17错误C2280

问题描述

我试图将最初用C#编写的Bencode库移植到C ++。

抽象基类

class BObjectBase
{
    protected:
        BObjectBase() = default;

    public:         
        virtual std::shared_ptr<BObjectBase> GetParent() = 0;           
};

抽象派生模板类

template<typename T>
class BObjectValue : public BObjectBase
{
    protected:
        BObjectValue() = default;

    public:
        virtual T GetValue() = 0;
};

通用派生类

template<typename T>
class BObject : public BObjectValue<T>
{
    private:
        const std::shared_ptr<BObjectBase> parent;
        const T value;

    protected:
        BObject(const std::shared_ptr<BObjectBase> p,const T v) : parent(p),value(v)
        {

        }

    public:
        std::shared_ptr<BObjectBase> GetParent()
        {
            return parent;
        }
        T GetValue()
        {
            return value;
        }
};

代表Bencoded整数的类

class BInteger : public BObject<long>
{
    public:
        BInteger(
            const std::shared_ptr<BObjectBase> parent,const long value)
                : BObject<long>(parent,value)
        {

        }
};

代表Bencoded字符串的类

class BString : public BObject<std::vector<std::byte>>
{
    public:
        BString(
            const std::shared_ptr<BObjectBase> parent,const std::vector<std::byte> value)
                : BObject<std::vector<std::byte>>(parent,value)
        {

        }
};

代表Bencoded列表的类

class BList : public BObject<std::vector<std::unique_ptr<BObjectBase>>>
{
    public:
        BList(
            const std::shared_ptr<BObjectBase> parent,const std::vector<std::unique_ptr<BObjectBase>> value)
                : BObject<std::vector<std::unique_ptr<BObjectBase>>>(parent,value)
        {
            
        }
};

两个类BInteger和BString都可以编译,但是BList失败。 双击错误会导致出现xmemory文件。

当我从unique_ptr切换到raw时,它会合规,这是我要避免的事情。

从早上开始,我就一直坚持下去。我是C ++的新手。这个想法是用C ++重写整个过程来学习C ++。

编译器-Microsoft VC ++在VS2019上设置为C ++ 17

严重性代码描述项目文件行抑制状态 错误C2280'std :: unique_ptr :: unique_ptr(const std :: unique_ptr &)':试图引用已删除的函数Bencode C:\ Program Files(x86 )\ Microsoft Visual Studio \ 2019 \ Community \ VC \ Tools \ MSVC \ 14.27.29110 \ include \ xmemory 694

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)