关于c++编译报隐式删除的错误

1.这个问题可能是父类对于某种方法设置了=delete 或者是private

2.某些拷贝构造函数报这种错误,可能是因为某些成员变量自身不支持拷贝导致的

I have class looks as follows in .h file (Header)

#include <boost/thread.hpp>

class MyClass{

    private:
        boost::mutex bPoolMtx_;

        // ... other vars
    public:
        // public vars and methods

}

I get the following error trying to build/ compile.

MyClass.h:38:7: note: ‘MyClass::MyClass(const MyClass&)’ is implicitly deleted because the default definition would be ill-formed:
MyClass.h:38:7: error: use of deleted function ‘boost::mutex::mutex(const boost::mutex&)’

I don't use the mutex at all in the cpp file yet. When I comment out the boost::mutex line it builds fine. What is going on?

 

5

 

The default copy constructor generated by the compiler copies all data members by default. Your use of boost::mutex throws an error because the mutex isn't copyable.

You can write your own copy constructor that doesn't attempt to copy the mutex or simply delete the copy constructor for MyClass.

#include <boost/thread.hpp>

class MyClass{
    private:
        boost::mutex bPoolMtx_;

        // ... other vars
    public:
        // public vars and methods
        MyClass(const MyClass&) = delete;
}

原文链接: https://www.cnblogs.com/wangshaowei/p/12156285.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    关于c++编译报隐式删除的错误

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/391367

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月31日 上午10:34
下一篇 2023年3月31日 上午10:34

相关推荐