How to initialize a container of noncopyable with initializer list?(如何使用初始化列表初始化不可复制的容器?)
问题描述
可能重复:
我可以列出初始化一个只移动类型的向量吗?
我使用 gcc 4.6.1 编译这段代码
I use gcc 4.6.1 to compile this code
在 g++ 的抱怨中,有类似的东西
In what g++ complains there is something like
在这种情况下,g++ 似乎仍在尝试复制构造函数,尽管我放入初始化列表的是 r 值.那么如何使用初始化列表初始化一个不可复制的容器呢?
It seems g++ still tries copy constructor in this case, though what I have put into initializer list are r-values. So how could I initialize a container of noncopyable with initializer list?
推荐答案
您不能将对象移出初始化列表,因为它们只允许对其成员进行 const 访问.因此,您不能使用初始化列表和移动构造函数;它们只能被复制.
You can't move objects out of initializer lists, since they only allow const access to their members. As such, you can't use initializer lists and move constructors; they can only be copied.
这篇关于如何使用初始化列表初始化不可复制的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!