dimanche 3 mai 2020

Class with std::map object and deleted copy assignment and constructor causes C2280 with std::pair's copy constructor

I'm trying to build my dll library after adding serialization classes to it. I have this code:

class VariablesSerializableValue
    : public SerializableValueBase
{
private:
    Serializable::Variables value;
public:
    VariablesSerializableValue() = default;
    VariablesSerializableValue(const VariablesSerializableValue&) = delete;

    VariablesSerializableValue(_In_ Serializable::Variables&& arg) noexcept;

    VariablesSerializableValue& operator=(const VariablesSerializableValue&) = delete;
    VariablesSerializableValue& operator=(_In_ Serializable::Variables&& arg) noexcept;

    const Serializable::Variables& getValue() const;

    void add(_In_ const String& name, _In_ UniquePtr<SerializableValueBase>&& arg);

    virtual UniquePtr<SerializableValueBase> clone() const override;
};

where SerializableValueBase is a polymorphic abstract class (code omitted, irrelevant). Serializable::Variables is defined as follows:

class GLOWE_DLLEXPORT Serializable
{
public:
    using Variables = Map<String, UniquePtr<Hidden::SerializableValueBase>>;
    ...

String is a no-throw-movable string class, UniquePtr is just a template using of std::unique_ptr. Map is a template using of std::map with my own memory allocator supplied.

When I try to compile this code, I get error C2280: 'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> &)': attempting to reference a deleted function. The error log says that the error is caused by Serializable::Variables value declaration in VariablesSerializableValue class. I have no idea what causes this although I explicitly deleted copy constructor and assignment in the class.

I tried to convert this code so that it uses PIMPL, but it just moved the error to the .cpp file where the implementation class was declared and defined. I have no idea how to tackle this. Any advice is much appreciated.

Aucun commentaire:

Enregistrer un commentaire