Попытка сослаться на удаленную функцию shared_ptr

у меня есть следующий код

inline entity_ptr Parser::parse(const std::string& json_str)
{
    // std::cout << "parse: " << json_str << "\n";
    entity_ptr entity = do_parse(json_str);
    if (entity && entity->is_notification())
    {
        notification_ptr notification = std::dynamic_pointer_cast<jsonrpcpp::Notification>(entity);
        if (notification_callbacks_.find(notification->method()) != notification_callbacks_.end())
        {
            notification_callback callback = notification_callbacks_[notification->method()];
            if (callback)
                callback(notification->params());
        }
    }
    else if (entity && entity->is_request())
    {
        request_ptr request = std::dynamic_pointer_cast<jsonrpcpp::Request>(entity);
        if (request_callbacks_.find(request->method()) != request_callbacks_.end())
        {
            request_callback callback = request_callbacks_[request->method()];
            if (callback)
            {
                jsonrpcpp::response_ptr response = callback(request->id(), request->params());
                if (response)
                    return response;
            }
        }
    }
    return entity;
}

При компиляции я получаю следующую ошибку

ошибка C2280: 'std::shared_ptrjsonrpcpp::Notification std::dynamic_pointer_castjsonrpcpp::Notification,jsonrpcpp::Entity(const std::shared_ptrjsonrpcpp::Entity &) noexcept': попытка сослаться на удаленную функцию

что касается класса уведомлений, то он следующий

class Notification : public Entity
{
public:
    Notification(const Json& json = nullptr);
    Notification(const char* method, const Parameter& params = nullptr);
    Notification(const std::string& method, const Parameter& params);

    Notification(const Notification&) = default;
    Notification(Notification &&) = default;
    Notification& operator=(const Notification&) = default;

    Json to_json() const override;
    void parse_json(const Json& json) override;

    const std::string& method() const
    {
        return method_;
    }

    const Parameter& params() const
    {
        return params_;
    }

protected:
    std::string method_;
    Parameter params_;
};

Насколько я понял, ошибка основана на том факте, что моя конструкция перемещения/параметра не реализована явно, хотя я их объявил, но все равно получаю ошибку, есть идеи, как это исправить?

Что касается базового класса, то он следующий

class Entity
{
public:

    Entity(entity_t type);
    virtual ~Entity() = default;
    Entity(const Entity&) = default;
    Entity& operator=(const Entity&) = default;
    Entity(Entity&&) = default;

    virtual std::string type_str() const;

    virtual Json to_json() const = 0;
    virtual void parse_json(const Json& json) = 0;

    virtual void parse(const std::string& json_str);
    virtual void parse(const char* json_str);

protected:
    entity_t entity;
};

Любая помощь будет оценена

Благодарить


person Zakkar    schedule 17.02.2021    source источник


Ответы (1)


По-видимому, плохо определенные переменные-члены могут привести к удалению функций по умолчанию. (как-то странно)

https://stackoverflow.com/a/37517125/2934222

Попробуйте изменить то, как вы определили этот метод, возможно:

virtual Json to_json() const = 0;

person Skewjo    schedule 17.02.2021
comment
Спасибо за ответ, но на самом деле это ничего не изменило, я заменил переменную на простой «виртуальный Json to_json();». но продолжайте получать ту же ошибку, надеюсь, что есть другой способ исправить это :( Спасибо - person Zakkar; 18.02.2021
comment
На самом деле изменение Dynamic на Static решило проблему. - person Zakkar; 18.02.2021