【问题标题】:implicitly deleted because the default definition would be ill-formed:隐式删除,因为默认定义格式不正确:
【发布时间】:2021-10-21 03:14:07
【问题描述】:
class Segment;
class Reactor;
class Client;
class Handler;

class SegmentInfo   
 64     {
 65     ▏   public:
 66     ▏   ▏   Segment segment;
 67     ▏   ▏   Reactor reactor;
 68     ▏   ▏   Client* client;
 69     ▏   ▏   queue<Handler*> pool;
 70 
 71     ▏   ▏   SegmentInfo(Segment _segment, int poolSize, Client* _client):
 72     ▏   ▏   ▏   segment(_segment), pool(poolSize), client(_client)
 73     ▏   ▏   {
 74 
 75     ▏   ▏   }
 76    };
error: use of deleted function ‘SegmentInfo::SegmentInfo(const SegmentInfo&)’

note: SegmentInfo::SegmentInfo(const SegmentInfo&)’ is implicitly deleted because the default definition would be ill-formed:


所以这是我的代码,我搜索了整个互联网,但找不到资源/链接/等。关于为什么会出现这个错误。所以如果你们能说出这个错误的根本原因以及如何解决它,那将非常有帮助!谢谢!!

【问题讨论】:

  • 你使用的是哪个编译器?
  • g++ 编译器。
  • 实际上我读了这个答案,但没有任何直觉,因为我没有使用任何constconstexpr
  • Segment 和 Reactor 有复制构造函数吗?

标签: c++


【解决方案1】:

我的猜测是SegmentInfo 有一个成员或继承自具有已删除复制构造函数的某人。请注意此示例如何给您同样的错误:

struct A
{
    A(const A&) = delete;
    A(){}
};

struct B
{ 
    A a;
};

int main()
{
    B b;
    B b2 = b;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 2013-11-21
    • 2021-11-06
    相关资源
    最近更新 更多