我有一個對象,我想要精確構造一次,因爲它所在的類通過向它們添加原始指針來跟蹤它的對象。構建它內嵌看來雖然失敗: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'添加到持有指針的靜態對象。 –