C ++正确的移动类的方法

时间:2017-02-09 18:53:59

标签: c++ c++11 std

我有处理(Vulkan)资源的类,让我们调用它们 VulkanInstanceVulkanDevice。 我的Master类拥有这两个

class Master {
    VulkanInstance instance_;
    VulkanDevice device_;
    reset();
}

在我的reset函数中,我想删除当前的instancedevice并创建一个新的device_。 我想到了以下条件:

    必须销毁
  1. instace_才能销毁device_,因为instance_取决于instance_
  2. 必须先创建
  3. device_才能创建device_
  4. instance_VulkanInstance无法复制,但可以构建,移动构造并移动分配
  5. 我想在删除旧的VulkanDeviceinstance_之前创建新的device_reset。因此,当我在构建新元素时遇到错误时,我仍然会留下旧的有效类。
  6. 我的问题是:我应该如何设计pointers功能。可以在不使用std::unique_ptr / VulkanInstanceVulkanDevice // PSEUDO CODE Master::reset() { VulkanInstance new_instance {}; VulkanDevice new_device {}; device_ = new_device; //use move here and destruct old device_ Dont use copy constructor instance_ = new_instance; //use move here and destruct old device_ Dont use copy constructor } 的情况下实现。

    我虽然喜欢这样的事情

    ...
    // to change/overwrite the initial string
    str = str.replace(re, function (match) {
    ...
    });
    

0 个答案:

没有答案
相关问题