我有以下代码
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_;
};
据我了解,错误是基于这样一个事实,即我的 move/param 构造在我声明它们但仍然收到错误时没有显式实现,知道如何解决它吗?
至于基类如下
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;
};
任何帮助,将不胜感激
感谢