对接口类使用互斥锁会导致派生类出现问题:“由于该函数是已删除的函数,因此无法引用”

我的代码运行良好,直到我向接口IPackage类添加了一些互斥锁。现在在Package类中,当我尝试store::IPackage P = *(new store::Package(args))时,我得到store::IPackage::IPackage(const store:IPackage&) (declared implicitly) Function cannot be referenced as it is a deleted function 取出互斥锁可以解决此问题。.我对C ++还是很陌生。有什么办法可以使这项工作吗?我认为我不能明确定义IPackage构造函数,因为它应该在界面中“隐藏”。

相关代码:

IPackage.h


    class IPackage {
    public:
        virtual ~IPackage() {}

        void SetTextDataPtr(std::vector<std::string>* _ptr);
        STORE_API std::vector<std::string>* GetTextDataPtr();
        std::mutex m_mutex_text_data_ptr;
        ...
        }
    ...

IPackage.cpp
void store::IPackage::SetTextDataPtr(std::vector<std::string>* _ptr) {
    std::lock_guard<std::mutex> lock(m_mutex_text_data_ptr);
    m_text_data_ptr = _ptr;
}
STORE_API std::vector<std::string>* store::IPackage::GetTextDataPtr() {
    //std::lock_guard<std::mutex> lock(m_mutex_text_data_ptr);
    return m_text_data_ptr;
}
...

Package.h
    class Package : public IPackage { //contains one .txt and one .jpg file
    public:
        Package(const std::filesystem::path &_parent_path,const std::string &_package_name,STORE_ERROR &_error);
    };
    ...
iCMS 回答:对接口类使用互斥锁会导致派生类出现问题:“由于该函数是已删除的函数,因此无法引用”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1763084.html

大家都在问