I have classes who handle (Vulkan) ressources, lets call them
VulkanInstance and VulkanDevice.
My Master class owns both of these
class Master {
VulkanInstance instance_;
VulkanDevice device_;
reset();
}
in my reset function i want to delete the current instance and device and create a new one.
I thought of the following conditions:
device_must be destroyed beforeinstace_can be destroyed, becausedevice_depends oninstance_instance_must be created beforedevice_can be createddevice_andinstance_can't be copied, however they can be constructed, move contructed and move assigned- i want to create a new
VulkanInstanceandVulkanDevicebefore deleting the oldinstance_anddevice_. So that when i get errors during construction of the new elements i still have the old valid classes left.
My question is: How should i design the reset function. Can it be realised without using pointers / std::unique_ptr to VulkanInstance or VulkanDevice.
I though about something like this
// 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
}