不生成隐式移动函数 [英] Implicit move functions not being generated

查看:148
本文介绍了不生成隐式移动函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下类:

class Blub
{
public:
  Blub(int value); // Not a copy constructor!
  Blub(Blub&&) = default; // This line is necessary because move constructor is not added automatically

  Blub& operator=(Blub&&) = default; // Does not work!?

  // Disallow copy
  Blub(Blub const &) = delete;
  Blub& operator=(Blub const &) = delete;
};

由于一些奇怪的原因,我不得不强制移动构造函数。
现在试图强制移动赋值操作符G ++(4.6.1)扼流:错误:'Blub& Blub :: operator =(Blub&& amp;)不能默认

For some strange reason I had to force the move constructor. Now trying to force the move assignment operator G++ (4.6.1) chokes with: error: 'Blub& Blub::operator=(Blub&&)' cannot be defaulted

很遗憾没有WHY。

解决方案:
实际上,我使用dragonegg插件来生成llvm代码。禁用dragonegg和使用正常的g ++默认值工作正常。
查看g ++的源代码不能是默认的(带移动赋值)消息是4.5(module.c)中的一个错误,但在4.6中得到修复。因为dragonegg依赖于g ++ 4.5我怀疑修复还没有。 Bummer。

The Solution: Actually I use the dragonegg plugin to generate llvm code. Disabling dragonegg and using normal g++ the defaulting works fine. Looking at the source of g++ the cannot be defaulted (with move assignment) message was a bug in 4.5 (module.c) but got fixed in 4.6.?. Since dragonegg does depend upon g++ 4.5 I suspect that the fix is not in yet. Bummer.

推荐答案

您必须随时强制移动构造函数声明复制构造函数或复制即使你 = default 它,C ++ 11也不会为你定义一个移动构造函数或赋值运算符。

You have to force a move constructor anytime you explicitly declare a copy constructor or copy assignment operator, even if you = default it, C++11 will not define a move constructor or assignment operator for you. Section 12.8 of the standard (paragraphs 9 and 20) explain the rules for when these are not declared.

对于为什么默认的移动构造函数不工作,标准的第12.8节(第9和20段)解释了这些未声明的规则。 d猜测,因为其他不支持移动操作。

As to why the default move constructor doesn't work, I'd guess that it's because Other doesn't support move operations.

这篇关于不生成隐式移动函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆