我有一个对象,我想要精确构造一次,因为它所在的类通过向它们添加原始指针来跟踪它的对象。构建它内嵌看来虽然失败:Emplace回到失败的地方建设
// Defined utilities:
ModuleClusterPlot(Type typeArg, const int& layer, const int& module, const int& ladder, const int& startEventArg, const int& endEventArg);
~ModuleClusterPlot();
// Invalid utilities
ModuleClusterPlot(ModuleClusterPlot& t_other) = delete;
ModuleClusterPlot(ModuleClusterPlot&& t_other) = delete;
ModuleClusterPlot& operator=(const ModuleClusterPlot& t_other) = delete;
ModuleClusterPlot& operator=(ModuleClusterPlot&& t_other) = delete;
调用通过布设构造回失败,因为它试图调用移动构造函数(为什么?):
moduleClusterPlots.emplace_back(t_type, t_layer, t_module, t_ladder, i, i);
什么我错在这里做什么?我正在使用gcc 7.1.0
和std=c++14
标志。
小例子:
#include <vector>
class ModuleClusterPlot
{
public:
enum Type
{
foo = 0,
bar
};
ModuleClusterPlot(Type typeArg);
~ModuleClusterPlot();
// Invalid utilities
ModuleClusterPlot(ModuleClusterPlot& t_other) = delete;
ModuleClusterPlot(ModuleClusterPlot&& t_other) = delete;
ModuleClusterPlot& operator=(const ModuleClusterPlot& t_other) = delete;
ModuleClusterPlot& operator=(ModuleClusterPlot&& t_other) = delete;
};
int main()
{
std::vector<ModuleClusterPlot> collection;
collection.emplace_back(ModuleClusterPlot::foo);
}
我怎样才能防止在这里调用移动构造函数?
你可以让这个[mcve]? – NathanOliver
你写你想要添加'原始指针',但如果你得到一个错误消息,需要一个复制/移动构造函数,我想你试图插入一个对象而不是指针! –
@ThomasSparber我将'this'添加到持有指针的静态对象。 –